-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday09.py
32 lines (25 loc) · 939 Bytes
/
day09.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
31
32
import time
from collections import deque,defaultdict
def playGame(players,lastmarble):
playerscores= defaultdict(int)
circle = deque([0])
for n in range(1,lastmarble+1):
if n%23 == 0:
circle.rotate(7)
playerscores[n%players]+= n + circle.pop()
circle.rotate(-1)
else:
circle.rotate(-1)
circle.append(n)
return playerscores
with open('./inputs/input9.txt') as f:
start_time= time.time()
line = f.readlines()[0].strip().split(" ")
players = int(line[0])
lastmarble = int(line[6])
playerscores = playGame(players,lastmarble)
print "Part one: "+str(playerscores[max(playerscores,key=playerscores.get)])
lastmarble= lastmarble*100
playerscoress = playGame(players,lastmarble)
print "Part two: "+str(playerscoress[max(playerscoress,key=playerscoress.get)])
print "Time: "+str(time.time()-start_time)