2020 day 15
This commit is contained in:
parent
4e82411915
commit
12e2fd4d74
|
@ -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)}')
|
Loading…
Reference in New Issue