day13
This commit is contained in:
parent
648212f24d
commit
4d94f7424b
52
day13.py
Normal file
52
day13.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
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)
|
||||||
44
inputs/input13
Normal file
44
inputs/input13
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
0: 3
|
||||||
|
1: 2
|
||||||
|
2: 6
|
||||||
|
4: 4
|
||||||
|
6: 4
|
||||||
|
8: 10
|
||||||
|
10: 6
|
||||||
|
12: 8
|
||||||
|
14: 5
|
||||||
|
16: 6
|
||||||
|
18: 8
|
||||||
|
20: 8
|
||||||
|
22: 12
|
||||||
|
24: 6
|
||||||
|
26: 9
|
||||||
|
28: 8
|
||||||
|
30: 8
|
||||||
|
32: 10
|
||||||
|
34: 12
|
||||||
|
36: 12
|
||||||
|
38: 8
|
||||||
|
40: 12
|
||||||
|
42: 12
|
||||||
|
44: 14
|
||||||
|
46: 12
|
||||||
|
48: 12
|
||||||
|
50: 12
|
||||||
|
52: 12
|
||||||
|
54: 14
|
||||||
|
56: 14
|
||||||
|
58: 14
|
||||||
|
60: 12
|
||||||
|
62: 14
|
||||||
|
64: 14
|
||||||
|
66: 17
|
||||||
|
68: 14
|
||||||
|
72: 18
|
||||||
|
74: 14
|
||||||
|
76: 20
|
||||||
|
78: 14
|
||||||
|
82: 18
|
||||||
|
86: 14
|
||||||
|
90: 18
|
||||||
|
92: 14
|
||||||
4
inputs/input13_test
Normal file
4
inputs/input13_test
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
0: 3
|
||||||
|
1: 2
|
||||||
|
4: 4
|
||||||
|
6: 4
|
||||||
Loading…
Reference in New Issue
Block a user