This commit is contained in:
Sebastian Seedorf
2020-12-15 09:47:24 +01:00
parent c116e1f37c
commit bf96e41ccb
3 changed files with 51 additions and 0 deletions

1
day15/input.txt Normal file
View File

@@ -0,0 +1 @@
0,13,16,17,1,10,6

25
day15/part1.py Normal file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env python3
from collections import defaultdict
lines = (x.strip() for x in open("input.txt"))
nums = defaultdict(list)
TARGET = 2020
for line in lines:
print(line)
turn = 0
last_spoken = 0
for starting in map(int, line.split(",")):
nums[starting] = [turn]
turn += 1
last_spoken = starting
for t in range(turn, TARGET):
last = nums[last_spoken]
if len(last) == 2:
n = last[1] - last[0]
else:
n = 0
nums[n] = nums[n][-1:] + [t]
last_spoken = n
print("->", last_spoken)

25
day15/part2.py Normal file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env python3
from collections import defaultdict
lines = (x.strip() for x in open("input.txt"))
nums = defaultdict(list)
TARGET = 30000000
for line in lines:
print(line)
turn = 0
last_spoken = 0
for starting in map(int, line.split(",")):
nums[starting] = [turn]
turn += 1
last_spoken = starting
for t in range(turn, TARGET):
last = nums[last_spoken]
if len(last) == 2:
n = last[1] - last[0]
else:
n = 0
nums[n] = nums[n][-1:] + [t]
last_spoken = n
print("->", last_spoken)