-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday15.py
36 lines (29 loc) · 946 Bytes
/
day15.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from util import Day
from aocd import submit
## Python's recursion limit is 1000, so we'll use iterations
def game(starting_numbers, max_num):
numbers = {k: i + 1 for i, k in enumerate(starting_numbers[:-1])}
next_num = starting_numbers[-1]
for i in range(len(starting_numbers), max_num):
idx = numbers.get(next_num, i)
# print(numbers, "spoken", next_num, "next", i-idx) # Good ol' print debugging
numbers[next_num] = i
next_num = i - idx
return next_num
def main(day, part=1):
if part == 1:
return game(day.data, 2020)
if part == 2:
return game(day.data, 30000000)
if __name__ == "__main__":
day = Day(15)
day.download()
day.load(sep=",")
# day.load(data, sep=",")
p1 = main(day)
print(p1)
submit(p1, part="a", day=15, year=2020)
day.load(sep=",")
p2 = main(day, part=2)
print(p2)
submit(p2, part="b", day=15, year=2020)