summary refs log tree commit diff
path: root/22.20/main.py
blob: c6324f51c110e0fbf4f03a79b9ae9e2eca4cbe09 (plain)
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
# brace for horribleness
from sys import stdin
a = [int(n) for n in stdin.readlines()]

def perm(a, p):
    for i, n in enumerate(a):
        og_idx = p.index(i)
        p.pop(og_idx)
        og_idx = (og_idx + n) % len(p)
        if og_idx == 0 and n < 0: og_idx = len(p)
        p.insert(og_idx, i)
    return p

def partOne(a):
    a = [a[i] for i in perm(a, list(range(len(a))))]
    def g(n): return a[(a.index(0) + n) % len(a)]
    return g(1000) + g(2000) + g(3000)

def partTwo(a):
    a = [n * 811589153 for n in a]
    p = list(range(len(a)))
    for _ in range(10):
        p = perm(a, p)
    a = [a[i] for i in p]
    def g(n): return a[(a.index(0) + n) % len(a)]
    return g(1000) + g(2000) + g(3000)

print(partOne(a))
print(partTwo(a))