Solve 2020 day 15

This commit is contained in:
felixm 2024-09-15 12:26:11 -04:00
parent 7986ecfc21
commit db383c7cfa
2 changed files with 24 additions and 1 deletions

22
2020/d15.py Normal file
View File

@ -0,0 +1,22 @@
from lib import get_data, str_to_ints
from collections import defaultdict
data = get_data(__file__)
for limit in [2021, 30000001]:
xs = list(reversed(str_to_ints(data)))
spoken = defaultdict(list)
recent = None
for turn in range(1, limit):
if len(xs) > 0:
recent = xs.pop()
spoken[recent].append(turn)
else:
if recent in spoken and len(spoken[recent]) == 1:
recent = 0
elif recent in spoken:
recent = spoken[recent][-1] - spoken[recent][-2]
else:
recent = 0
spoken[recent].append(turn)
print(recent)

View File

@ -150,7 +150,8 @@ Solutions and utility script for Advent of Code challenges in Python.
- Day 12: 21:52 (just slow again for an easy problem)
- Day 13: 18:00 (I don't really understand the CRT to be honest)
- Day 14: 40:26 (Made a bunch of mistakes even misunderstanding Python)
- Day 15:
- Day 15: 17:57 (Too slow for an easy one like this)
- Day 16:
## AoC 2022