-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_9.py
69 lines (55 loc) · 1.24 KB
/
day_9.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# part 2, remove the * 100 for part 1
import time
import math
import collections
import re
current_milli_time = lambda: int(round(time.time() * 1000))
start = current_milli_time()
# Input
players = 431
lastpoint = 70950
circle = collections.deque()
circle.append(0)
elf = 0
maxscore = 0
scores = collections.defaultdict(int)
player = 1
for x in range(1, lastpoint+1):
if (x % 23) == 0:
circle.rotate(-7)
scores[player] += (x + circle.pop())
if scores[player] > maxscore:
maxscore = scores[player]
elf = player
else:
circle.rotate(2)
circle.append(x)
player += 1
if player > players:
player = 1
print("Part 1: ", maxscore)
# print((current_milli_time() - start) / 1000.0)
#Part 2
players = 431
lastpoint = 70950*100
circle = collections.deque()
circle.append(0)
elf = 0
maxscore = 0
scores = collections.defaultdict(int)
player = 1
for x in range(1, lastpoint+1):
if (x % 23) == 0:
circle.rotate(-7)
scores[player] += (x + circle.pop())
if scores[player] > maxscore:
maxscore = scores[player]
elf = player
else:
circle.rotate(2)
circle.append(x)
player += 1
if player > players:
player = 1
print("Part 2: ", maxscore)
# print((current_milli_time() - start) / 1000.0)