-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday20.py
50 lines (43 loc) · 1011 Bytes
/
day20.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
class Node:
def __init__(self, n):
self.n = n
self.left = None
self.right = None
x = [Node(int(x)) for x in open('input_day20.txt')]
for i in range(len(x)):
x[i].right = x[(i + 1) % len(x)]
x[i].left = x[(i - 1) % len(x)]
m = len(x) - 1
for k in x:
if k.n == 0:
z = k
continue
p = k
if k.n > 0:
for _ in range(k.n % m):
p = p.right
if k == p:
continue
k.right.left = k.left
k.left.right = k.right
p.right.left = k
k.right = p.right
p.right = k
k.left = p
else:
for _ in range(-k.n % m):
p = p.left
if k == p:
continue
k.left.right = k.right
k.right.left = k.left
p.left.right = k
k.left = p.left
p.left = k
k.right = p
t = 0
for _ in range(3):
for _ in range(1000):
z = z.right
t += z.n
print(t)