-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay15_Part1.py
30 lines (28 loc) · 1016 Bytes
/
Day15_Part1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from collections import defaultdict
input=[0,20,7,16,1,18,15]
num_log=defaultdict()
turn_counter=1
last_said=0
for el in input:
num_log[el]={'last':turn_counter,'time_before_last':turn_counter}
last_said=el
turn_counter+=1
rounds=2020
while turn_counter<=rounds:
if last_said in num_log.keys():
next_num=num_log[last_said]['last']-num_log[last_said]['time_before_last']
last_said=next_num
if next_num in num_log.keys():
num_log[next_num]['time_before_last']=num_log[next_num]['last']
num_log[next_num]['last']=turn_counter
else:
num_log[next_num]={'last':turn_counter,'time_before_last':turn_counter}
else:
next_num=0
if next_num in num_log.keys():
num_log[next_num]['time_before_last']=num_log[next_num]['last']
num_log[next_num]['last']=turn_counter
else:
num_log[next_num]={'last':turn_counter,'time_before_last':turn_counter}
turn_counter+=1
print(last_said)