aoc2022/d20/part2.py

52 lines
810 B
Python
Raw Normal View History

from __future__ import annotations
import sys
from dataclasses import dataclass
@dataclass
class E:
v: int
p: E
n: E
DEK = 811589153
V0 = None
p = None
L = []
for l in sys.stdin.read().splitlines():
e = E(int(l)*DEK,p,None)
L.append(e)
if l == "0":
V0 = e
if p is not None:
p.n = e
p = e
L[-1].n = L[0]
L[0].p = L[-1]
def swap(l,m):
k = l.p
n = m.n
k.n = m
n.p = l
l.n = n
m.p = k
l.p = m
m.n = l
for _ in range(10):
for l in L:
if l.v > 0:
for _ in range(l.v%(len(L)-1)):
swap(l,l.n)
elif l.v < 0:
for _ in range(-l.v%(len(L)-1)):
swap(l.p,l)
S = 0
s = V0
for i in range(3000+1):
if i in [1000,2000,3000]:
S += s.v
s = s.n
print(S)