day 11, no room for dignity

This commit is contained in:
setop 2022-12-11 14:04:43 +01:00
parent 9f935aedf7
commit ba932dcc92
6 changed files with 187 additions and 0 deletions

45
d11/input1.py Normal file
View File

@ -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
]
]

50
d11/input2.py Normal file
View File

@ -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
]
]

18
d11/part1.py Normal file
View File

@ -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])

20
d11/part2.py Normal file
View File

@ -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])

24
d11/sample1.py Normal file
View File

@ -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
]
]

30
d11/sample2.py Normal file
View File

@ -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
]
]