Skip to content

Instantly share code, notes, and snippets.

@aledesole
Last active December 17, 2020 10:56
Show Gist options
  • Save aledesole/4b1a1a3cddfc059857e61250833cf089 to your computer and use it in GitHub Desktop.
Save aledesole/4b1a1a3cddfc059857e61250833cf089 to your computer and use it in GitHub Desktop.
Advent of code 2020, Day 14, Python3.9
from sys import stdin
from functools import reduce
def play(s,i):
stor,l = s
j=i-1-stor.get(l,i-1)
stor[l]=i-1
return (stor,j)
I=[int(i) for i in stdin.readline().split(',')]
for t in (2021, 30000001):
print(
reduce(play,
range(len(I)+1,t),
({i:turn for turn,i in enumerate(I,1)},
I[-1]))[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment