summary refs log tree commit diff
path: root/22.20
diff options
context:
space:
mode:
authordzwdz2022-12-20 23:19:31 +0100
committerdzwdz2022-12-20 23:19:31 +0100
commit529b8303374f68d88f993af55d53b8dd32d8ea13 (patch)
tree737c2944e5d75dabead899c74edea8e2b5ef5921 /22.20
parent4b7e027f5ac3cf1f62f986573708f3a85aa1d955 (diff)
day 20 part 2
just wanted to get this over with
Diffstat (limited to '22.20')
-rw-r--r--22.20/main.py33
1 files changed, 23 insertions, 10 deletions
diff --git a/22.20/main.py b/22.20/main.py
index 7cb46de..c6324f5 100644
--- a/22.20/main.py
+++ b/22.20/main.py
@@ -1,16 +1,29 @@
+# brace for horribleness
 from sys import stdin
 a = [int(n) for n in stdin.readlines()]
 
-p = list(range(len(a)))
+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
 
-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)
+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)
 
-a = [a[i] for i in p]
-def g(n): return a[(a.index(0) + n) % len(a)]
+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(g(1000) + g(2000) + g(3000))
+print(partOne(a))
+print(partTwo(a))