day 20 python solution

main
magical 2022-12-19 21:34:48 -08:00
parent 47c10a1027
commit 009fa446c2
2 changed files with 5046 additions and 0 deletions

5000
day20/input 100644

File diff suppressed because it is too large Load Diff

46
day20/sol.py 100644
View File

@ -0,0 +1,46 @@
data = []
for line in open("input"):
data.append(int(line.strip()))
#data = [1, 2, -3, 3, -2, 0, 4, ]
def mix(data, rounds=1):
#assert len(set(data)) == len(data)
copy = list(data)
idx = list(range(len(data)))
for _ in range(rounds):
for k in range(len(data)):
i = idx.index(k)
x = copy[i]
if x != 0:
j = (i+x) % (len(copy)-1)
if x < 0 and j == 0:
j = len(copy)-1
copy.insert(j, copy.pop(i))
idx.insert(j, idx.pop(i))
else:
j = i
#print(x, i, j, copy)
return copy
def answer(data):
i = data.index(0)
n = 0
for j in 1000, 2000, 3000:
x = data[(i+j)%len(copy)]
#print(x)
n += x
return n
#print(copy)
copy = mix(data)
print(answer(copy))
p2 = [x*811589153 for x in data]
print(answer(mix(p2, 10)))