aoc2020/15/2.py

22 lines
357 B
Python
Raw Normal View History

2020-12-15 10:04:21 +01:00
content = [2,0,6,12,1,3]
spoken = {}
2020-12-15 10:21:30 +01:00
new_spoken = 0
2020-12-15 10:04:21 +01:00
turn = 1
for c in content:
spoken[c] = turn
turn += 1
2020-12-15 10:21:30 +01:00
last_turn = 0
while turn <= 30000000:
if not last_turn:
2020-12-15 10:04:21 +01:00
new_spoken = 0
else:
new_spoken = turn - 1 - last_turn
2020-12-15 10:21:30 +01:00
last_turn = spoken.get(new_spoken, 0)
2020-12-15 10:04:21 +01:00
spoken[new_spoken] = turn
2020-12-15 10:21:30 +01:00
turn += 1
2020-12-15 10:04:21 +01:00
2020-12-15 10:21:30 +01:00
print(new_spoken)