2020: d13: ex1: add solution

This commit is contained in:
Bruno BELANYI 2020-12-13 07:38:51 +01:00
parent 35bb7637a5
commit 769d2f7079

31
2020/d13/ex1/ex1.py Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env python
import itertools
import math
import sys
from typing import List, Tuple
def find_first_factor(earliest: int, timings: List[int]) -> Tuple[int, int]:
timings = sorted(timings)
for t in itertools.count(earliest):
for n in timings:
if t % n == 0:
return t - earliest, n
assert False # Make Mypy happy
def solve(raw: List[str]) -> int:
return math.prod(
find_first_factor(int(raw[0]), [int(i) for i in raw[1].split(",") if i != "x"])
)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()