2020 day 15

This commit is contained in:
Luke Hubmayer-Werner 2020-12-15 16:48:56 +10:30
parent 4e82411915
commit 12e2fd4d74
1 changed files with 17 additions and 0 deletions

17
2020/day15.py Normal file
View File

@ -0,0 +1,17 @@
def play_game(data, until):
last_indices = {v:i for i,v in enumerate(data[:-1])}
last = data[-1]
for i in range(len(data), until):
if last in last_indices:
n = i-last_indices[last]-1
last_indices[last] = i-1
last = n
else:
last_indices[last] = i-1
last = 0
return last
input = [int(i) for i in '10,16,6,0,1,17'.split(',')]
print(f'Part 1: 2020th number is {play_game(input, 2020)}')
print(f'Part 2: 30000000th number is {play_game(input, 30000000)}')