-
Notifications
You must be signed in to change notification settings - Fork 0
/
day20.py
71 lines (59 loc) · 1.46 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class ListNode:
def __init__(self, val, next = None):
self.val = val
self.next = next
#self.prev = prev
def makeInput(file):
with open(file) as f:
lines = f.readlines()
lst = []
prev = None
for x in lines:
current = ListNode(int(x.strip()) * 811589153)
if current.val == 0:
zero = current
#current.prev = prev
if prev:
prev.next = current
lst.append(current)
prev = current
current.next = lst[0]
#lst[0].prev = current
return lst, zero
file = 'day20.txt'
order, zero = makeInput(file)
llst = order.copy()
i = 0
n = len(order)
current = order[0]
# for j in range(n):
# print(order[j].val)
# print(current.val)
# current = current.next
for _ in range(10):
print(_)
for i in range(n):
current = order[i]
prev = current
while prev.next != current:
prev = prev.next
val = current.val % (n-1)
#print(val)
for _ in range(val):
curNext = current.next
current.next = curNext.next
curNext.next = current
prev.next = curNext
prev = curNext
current = zero
# temp = zero
# for _ in range(n):
# print(temp.val)
# temp = temp.next
totalSum = 0
for i in range(3):
for j in range(1000):
current = current.next
print(i,current.val)
totalSum += current.val
print("totalSum = ", totalSum)