Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def solve(match):
pdict = {}
for i, p in enumerate(data):
pdict[int(p)] = i + 1
turn = len(pdict) + 1
same = 0
while turn < match:
if same in pdict:
diff = turn - pdict[same]
pdict[same] = turn
else:
diff = 0
pdict[same] = turn
same = diff
turn += 1
return same
data = open("day15.in").read().strip().split(',')
print(f'Part 1: {solve(2020)}')
print(f'Part 2: {solve(30000000)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment