-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc20b.py
111 lines (93 loc) · 2.94 KB
/
aoc20b.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from aoc_util import *
import copy
import itertools
from functools import reduce
import re
import heapq
data = numbers(get_data(20))
# data = numbers("""
# 1
# 2
# -3
# 3
# -2
# 0
# 4
# """)
order = list(range(len(data)))
for (idx, val) in enumerate(data):
# print(idx, val, len(set(order)))
curridx = order[idx]
rval = val % (len(data) - 1)
secondidx = curridx + rval
if secondidx >= len(data):
secondidx = curridx - (len(data) - 1) + rval
#secondidx = (curridx + (val % (len(data) - 1))) % len(data)
neworder = list(order)
if secondidx < curridx:
neworder = [i+1 if secondidx <= i < curridx else i for i in neworder]
neworder[idx] = secondidx
# print("<", idx, val, curridx, secondidx, len(set(neworder)))
elif curridx < secondidx:
neworder = [i-1 if curridx < i <= secondidx else i for i in neworder]
neworder[idx] = secondidx
# print("<", idx, val, curridx, secondidx, len(set(neworder)))
order = neworder
assert len(set(order)) == len(data)
#print("order", order)
tvals = [None] * len(data)
for (idx, ord) in enumerate(order):
tvals[ord] = data[idx]
#print("tvals", tvals)
orderinv = [None] * len(data)
for (idx, val) in enumerate(order):
orderinv[val] = idx
# print(order)
# print(orderinv)
zeroidx = data.index(0)
zerospot = order[zeroidx]
tot = 0
for off in (1000, 2000, 3000):
sp = (off + zerospot) % len(data)
# print(data[orderinv[sp]])
tot += data[orderinv[sp]]
print(tot)
order = list(range(len(data)))
for _ in range(10):
for (idx, val) in enumerate(data):
# print(idx, val, len(set(order)))
curridx = order[idx]
rval = (val*811589153) % (len(data) - 1)
secondidx = curridx + rval
if secondidx >= len(data):
secondidx = curridx - (len(data) - 1) + rval
#secondidx = (curridx + (val % (len(data) - 1))) % len(data)
neworder = list(order)
if secondidx < curridx:
neworder = [i+1 if secondidx <= i < curridx else i for i in neworder]
neworder[idx] = secondidx
# print("<", idx, val, curridx, secondidx, len(set(neworder)))
elif curridx < secondidx:
neworder = [i-1 if curridx < i <= secondidx else i for i in neworder]
neworder[idx] = secondidx
# print("<", idx, val, curridx, secondidx, len(set(neworder)))
order = neworder
assert len(set(order)) == len(data)
#print("order", order)
tvals = [None] * len(data)
for (idx, ord) in enumerate(order):
tvals[ord] = data[idx]
#print("tvals", tvals)
orderinv = [None] * len(data)
for (idx, val) in enumerate(order):
orderinv[val] = idx
# print(order)
# print(orderinv)
zeroidx = data.index(0)
zerospot = order[zeroidx]
tot = 0
for off in (1000, 2000, 3000):
sp = (off + zerospot) % len(data)
# print(data[orderinv[sp]])
tot += 811589153*data[orderinv[sp]]
print(tot)