53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
from tools.aoc import AOCDay
|
|
from typing import Any
|
|
|
|
|
|
def get_caught_mul(init: dict, delay: int = 0) -> int:
|
|
caught = 0
|
|
for x, s in init.items():
|
|
if (x + delay) % (s * 2) == 0:
|
|
if delay:
|
|
return 1
|
|
else:
|
|
caught += x * (s + 1)
|
|
|
|
return caught
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(24, "input13_test"),
|
|
(3184, "input13")
|
|
],
|
|
[
|
|
(10, "input13_test"),
|
|
(3878062, "input13")
|
|
]
|
|
]
|
|
|
|
def get_input(self) -> dict:
|
|
ret = {}
|
|
state = {}
|
|
for line in self.getInput():
|
|
l, d = map(int, line.split(": "))
|
|
ret[l] = d - 1
|
|
state[l] = [0, -1]
|
|
|
|
return ret
|
|
|
|
def part1(self) -> Any:
|
|
return get_caught_mul(self.get_input())
|
|
|
|
def part2(self) -> Any:
|
|
delay = 0
|
|
init = self.get_input()
|
|
while get_caught_mul(init, delay):
|
|
delay += 1
|
|
return delay
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2017, 13)
|
|
day.run(verbose=True)
|