From 6a9d3da72568f4f32ca13e3491cdc97a7e3b48fd Mon Sep 17 00:00:00 2001 From: setop Date: Sun, 11 Dec 2022 21:07:16 +0100 Subject: [PATCH] day 11, compact --- d11/run.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 d11/run.py diff --git a/d11/run.py b/d11/run.py new file mode 100644 index 0000000..c376c43 --- /dev/null +++ b/d11/run.py @@ -0,0 +1,35 @@ +import sys +from math import prod + +part = int(sys.argv[1]) +T = sys.stdin.read().split('\n\n') +M = [] # monkey: 0:items, 1:func, 2:divider, 3:iftrue, 4:iffalse, 5:count +D = 1 +for t in T: + u = t.split('\n') + m = [] + m.append([int(i) for i in u[1].split(':')[1].split(',')]) + m.append(u[2].split("=")[1]) + d = int(u[3].split(" ")[-1]) + m.append(d) # devider + D *= d + m.append(int(u[4].split(" ")[-1])) + m.append(int(u[5].split(" ")[-1])) + m.append(0) + M.append(m) + +for _ in range(20 if part==1 else 10000): + for k,m in enumerate(M): + for i in m[0]: + m[5] += 1 + ni = eval(m[1].replace("old", str(i))) % D + if part == 1: + ni = ni // 3 + nm = m[4] if ni % m[2] else m[3] + M[nm][0].append(ni) + m[0] = [] + +L=list(m[5] for m in M) +print(L) +LS=list(sorted(L)) +print(LS[-1]*LS[-2]) \ No newline at end of file