2018: d02: ex1: add solution
This commit is contained in:
parent
8da9ad7eb6
commit
7eeab208b0
24
2018/d02/ex1/ex1.py
Executable file
24
2018/d02/ex1/ex1.py
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def solve(input: str) -> int:
|
||||
def any_letter(boxes: list[str], count: int) -> int:
|
||||
return sum(count in Counter(box).values() for box in boxes)
|
||||
|
||||
def checksum(boxes: list[str]) -> int:
|
||||
return any_letter(boxes, 2) * any_letter(boxes, 3)
|
||||
|
||||
boxes = input.splitlines()
|
||||
return checksum(boxes)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue