From ba932dcc92864a305e40da57fe174f37beb8a035 Mon Sep 17 00:00:00 2001 From: setop Date: Sun, 11 Dec 2022 14:04:43 +0100 Subject: [PATCH] day 11, no room for dignity --- d11/input1.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ d11/input2.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ d11/part1.py | 18 ++++++++++++++++++ d11/part2.py | 20 ++++++++++++++++++++ d11/sample1.py | 24 ++++++++++++++++++++++++ d11/sample2.py | 30 ++++++++++++++++++++++++++++++ 6 files changed, 187 insertions(+) create mode 100644 d11/input1.py create mode 100644 d11/input2.py create mode 100644 d11/part1.py create mode 100644 d11/part2.py create mode 100644 d11/sample1.py create mode 100644 d11/sample2.py diff --git a/d11/input1.py b/d11/input1.py new file mode 100644 index 0000000..a205223 --- /dev/null +++ b/d11/input1.py @@ -0,0 +1,45 @@ +from collections import deque + +M = [ +[ + deque([ 84, 72, 58, 51]) + , lambda old: old * 3 + , lambda x: 7 if divmod(x,13)[1] else 1 + ,0 +],[ + deque([ 88, 58, 58 ]) + , lambda old: old + 8 + , lambda x: 5 if divmod(x,2)[1] else 7 + ,0 +],[ + deque([ 93, 82, 71, 77, 83, 53, 71, 89]) + , lambda old: old * old + , lambda x: 4 if divmod(x,7)[1] else 3 + ,0 +],[ + deque([ 81, 68, 65, 81, 73, 77, 96]) + , lambda old: old + 2 + , lambda x: 6 if divmod(x,17)[1] else 4 + ,0 +],[ + deque([ 75, 80, 50, 73, 88]) + , lambda old: old + 3 + , lambda x: 0 if divmod(x,5)[1] else 6 + ,0 +],[ + deque([ 59, 72, 99, 87, 91, 81]) + , lambda old: old * 17 + , lambda x: 3 if divmod(x,11)[1] else 2 + ,0 +],[ + deque([ 86, 69]) + , lambda old: old + 6 + , lambda x: 0 if divmod(x,3)[1] else 1 + ,0 +],[ + deque([ 91]) + , lambda old: old + 1 + , lambda x: 5 if divmod(x,19)[1] else 2 + , 0 +] +] \ No newline at end of file diff --git a/d11/input2.py b/d11/input2.py new file mode 100644 index 0000000..8bdd68e --- /dev/null +++ b/d11/input2.py @@ -0,0 +1,50 @@ +from collections import deque + +PRIMES = (13,2,7,17,5,11,3,19) + +def mods(x): + return [x%i for i in PRIMES] + +M = [ +[ + deque(mods(x) for x in [ 84, 72, 58, 51]) + , lambda old: [((o%i)*(3%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 7 if x[0] else 1 + ,0 +],[ + deque(mods(x) for x in [ 88, 58, 58 ]) + , lambda old: [((o%i)+(8%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 5 if x[1] else 7 + ,0 +],[ + deque(mods(x) for x in [ 93, 82, 71, 77, 83, 53, 71, 89]) + , lambda old: [((o%i)*(o%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 4 if x[2] else 3 + ,0 +],[ + deque(mods(x) for x in [ 81, 68, 65, 81, 73, 77, 96]) + , lambda old: [((o%i)+(2%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 6 if x[3] else 4 + ,0 +],[ + deque(mods(x) for x in [ 75, 80, 50, 73, 88]) + , lambda old: [((o%i)+(3%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 0 if x[4] else 6 + ,0 +],[ + deque(mods(x) for x in [ 59, 72, 99, 87, 91, 81]) + , lambda old: [((o%i)*(17%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 3 if x[5] else 2 + ,0 +],[ + deque(mods(x) for x in [ 86, 69]) + , lambda old: [((o%i)+(6%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 0 if x[6] else 1 + ,0 +],[ + deque(mods(x) for x in [ 91]) + , lambda old: [((o%i)+(1%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 5 if x[7] else 2 + ,0 +] +] \ No newline at end of file diff --git a/d11/part1.py b/d11/part1.py new file mode 100644 index 0000000..8f12502 --- /dev/null +++ b/d11/part1.py @@ -0,0 +1,18 @@ +import sys +mod = __import__(sys.argv[1]) + +M = mod.M +for r in range(20): + for k,m in enumerate(M): + items = m[0] + m[3] += len(items) + for _ in range(len(items)): + i = items.popleft() + ni = m[1](i) // 3 + nm = m[2](ni) + M[nm][0].append(ni) + +L=list(m[3] for m in M) +print(L) +LS=list(sorted(L)) +print(LS[-1]*LS[-2]) \ No newline at end of file diff --git a/d11/part2.py b/d11/part2.py new file mode 100644 index 0000000..694cb87 --- /dev/null +++ b/d11/part2.py @@ -0,0 +1,20 @@ +import sys +mod = __import__(sys.argv[1]) + +M = mod.M +for r in range(10*1000): + print(f"\rround {r+1}",end='') + for m in M: + items = m[0] + m[3] += len(items) + for _ in range(len(items)): + i = items.popleft() + ni = m[1](i) #// 3 + nm = m[2](ni) + M[nm][0].append(ni) +print() + +L=list(m[3] for m in M) +print(L) +LS=list(sorted(L)) +print(LS[-1]*LS[-2]) diff --git a/d11/sample1.py b/d11/sample1.py new file mode 100644 index 0000000..53d58c5 --- /dev/null +++ b/d11/sample1.py @@ -0,0 +1,24 @@ +from collections import deque +M = [ +[ + deque([ 79, 98 ]) + , lambda old: old * 19 + , lambda x: 3 if divmod(x,23)[1] else 2 + ,0 +],[ + deque([ 54, 65, 75, 74 ]) + , lambda old: old + 6 + , lambda x: 0 if divmod(x,19)[1] else 2 + ,0 +],[ + deque([ 79, 60, 97 ]) + , lambda old: old * old + , lambda x: 3 if divmod(x,13)[1] else 1 + ,0 +],[ + deque([ 74 ]) + , lambda old: old + 3 + , lambda x: 1 if divmod(x,17)[1] else 0 + ,0 +] +] diff --git a/d11/sample2.py b/d11/sample2.py new file mode 100644 index 0000000..e9606cd --- /dev/null +++ b/d11/sample2.py @@ -0,0 +1,30 @@ +from collections import deque + +PRIMES = (23,19,13,17) + +def mods(x): + return [x%i for i in PRIMES] + +M = [ +[ + deque(mods(x) for x in [ 79, 98 ]) + , lambda old: [((o%i)*(19%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 3 if x[0] else 2 + ,0 +],[ + deque(mods(x) for x in [ 54, 65, 75, 74 ]) + , lambda old: [((o%i)+(6%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 0 if x[1] else 2 + ,0 +],[ + deque(mods(x) for x in [ 79, 60, 97 ]) + , lambda old: [((o%i)*(o%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 3 if x[2] else 1 + ,0 +],[ + deque(mods(x) for x in [ 74 ]) + , lambda old: [((o%i)+(3%i))%i for (o,i) in zip(old,PRIMES)] + , lambda x: 1 if x[3] else 0 + ,0 +] +]