day 20 python cleanup
parent
009fa446c2
commit
cb4b8295e1
24
day20/sol.py
24
day20/sol.py
|
@ -7,36 +7,34 @@ for line in open("input"):
|
||||||
|
|
||||||
def mix(data, rounds=1):
|
def mix(data, rounds=1):
|
||||||
#assert len(set(data)) == len(data)
|
#assert len(set(data)) == len(data)
|
||||||
copy = list(data)
|
|
||||||
idx = list(range(len(data)))
|
idx = list(range(len(data)))
|
||||||
|
N = len(data) - 1
|
||||||
|
|
||||||
for _ in range(rounds):
|
for _ in range(rounds):
|
||||||
|
|
||||||
for k in range(len(data)):
|
for k in range(len(data)):
|
||||||
i = idx.index(k)
|
i = idx.index(k)
|
||||||
x = copy[i]
|
x = data[k]
|
||||||
if x != 0:
|
if x != 0:
|
||||||
j = (i+x) % (len(copy)-1)
|
j = (i+x) % N
|
||||||
if x < 0 and j == 0:
|
if x < 0 and j == 0:
|
||||||
j = len(copy)-1
|
j = N
|
||||||
copy.insert(j, copy.pop(i))
|
|
||||||
idx.insert(j, idx.pop(i))
|
idx.insert(j, idx.pop(i))
|
||||||
else:
|
else:
|
||||||
j = i
|
j = i
|
||||||
#print(x, i, j, copy)
|
#print(x, i, j, [data[k] for k in idx])
|
||||||
|
|
||||||
return copy
|
return [data[k] for k in idx]
|
||||||
|
|
||||||
def answer(data):
|
def answer(data):
|
||||||
i = data.index(0)
|
i = data.index(0)
|
||||||
n = 0
|
n = []
|
||||||
for j in 1000, 2000, 3000:
|
for j in 1000, 2000, 3000:
|
||||||
x = data[(i+j)%len(copy)]
|
n.append( data[(i+j)%len(data)] )
|
||||||
#print(x)
|
print(n)
|
||||||
n += x
|
return sum(n)
|
||||||
return n
|
|
||||||
|
|
||||||
#print(copy)
|
#print(data)
|
||||||
|
|
||||||
copy = mix(data)
|
copy = mix(data)
|
||||||
print(answer(copy))
|
print(answer(copy))
|
||||||
|
|
Loading…
Reference in New Issue