2017: d02: ex2: add solution
This commit is contained in:
parent
c31f2128f5
commit
3e6fb347c0
1 changed files with 29 additions and 0 deletions
29
2017/d02/ex2/ex2.py
Executable file
29
2017/d02/ex2/ex2.py
Executable file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import itertools
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def solve(input: str) -> int:
|
||||||
|
def parse(input: str) -> list[list[int]]:
|
||||||
|
return [[int(n) for n in line.split()] for line in input.splitlines()]
|
||||||
|
|
||||||
|
def evenly_divide(row: list[int]) -> int:
|
||||||
|
for a, b in itertools.combinations(sorted(row), 2):
|
||||||
|
assert a <= b # Sanity check
|
||||||
|
if b % a:
|
||||||
|
continue
|
||||||
|
return b // a
|
||||||
|
assert False # Sanity check
|
||||||
|
|
||||||
|
sheet = parse(input)
|
||||||
|
return sum(map(evenly_divide, sheet))
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
input = sys.stdin.read()
|
||||||
|
print(solve(input))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue