aoc2020/15/1.py
Juan José Gutiérrez de Quevedo Pérez dd2497438d optimized versions of day 15
interesting discoveries:
  * using a list instead of a dict made a difference, but not a lot
  * declaring the code in a function instead of as "global code" made *A
    LOT* of difference. I guess it has to do with the variables being
    global in that case
2020-12-15 11:40:03 +01:00

25 lines
485 B
Python

def play_number_of_turns(turns):
content = [2,0,6,12,1,3]
spoken = [0] * turns
new_spoken = 0
turn = 1
for c in content:
spoken[c] = turn
turn += 1
last_turn = 0
while turn <= turns:
if not last_turn:
new_spoken = 0
else:
new_spoken = turn - 1 - last_turn
last_turn = spoken[new_spoken]
spoken[new_spoken] = turn
turn += 1
print(new_spoken)
play_number_of_turns(2020)