Skip to content

Instantly share code, notes, and snippets.

@prdoyle
Created December 15, 2020 14:20
Show Gist options
  • Save prdoyle/a9c0676eaa0aabe65d5bb24975460382 to your computer and use it in GitHub Desktop.
Save prdoyle/a9c0676eaa0aabe65d5bb24975460382 to your computer and use it in GitHub Desktop.
Advent of code 2020
#! /usr/bin/python
seed = [0,12,6,13,20,1,17]
end = 30000000
position = 1
most_recent = {}
def process( num ):
global position, most_recent
try:
result = position - most_recent[ num ]
except KeyError:
result = 0
most_recent[ num ] = position
position += 1
return result
for n in seed:
last = process( n )
# We want item at index end-1 (the end'th item), which is the return value from the end-2'th call to process
for n in range( len(seed), end-1 ):
last = process( last )
print( last )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment