This commit is contained in:
setop 2022-01-02 23:35:19 +01:00
parent e3c1f47592
commit a877bc5bed
5 changed files with 178 additions and 0 deletions

22
d14/d14_1.py Normal file
View File

@ -0,0 +1,22 @@
import sys
L = sys.stdin.read().splitlines()
seed = L[0]
L = L[2:]
L = [ l.split() for l in L ]
D = { tuple(k):v for [k,_,v] in L }
print(seed, D)
for step in range(10):
C = ["X"] # X is their to avoid empty list when comparing to previous char
for (a,b) in zip(seed, seed[1:]):
if a != C[-1]:
C.append(a)
if (a,b) in D:
C.append(D[(a,b)])
C.append(b)
seed = "".join(C)
print(step+1, len(seed), seed[1:])
from collections import Counter
C = Counter(seed)
del C["X"]
print(C, C.values(), max(C.values())-min(C.values()))
# store 40 iterations will be 20*2^39~=21TB ...

27
d14/d14_2.py Normal file
View File

@ -0,0 +1,27 @@
import sys
L = sys.stdin.read().splitlines()
seed = L[0]
L = L[2:]
L = [ l.split() for l in L ]
D = { tuple(k):v for [k,_,v] in L }
def reprpairs(P):
return " ".join(f"{a}{b}:{v}" for ((a,b),v) in P.items())
E = { K:0 for (K,_) in D.items() }
for (a,b) in zip(seed, seed[1:]):
E[(a,b)] += 1
#print(reprpairs(E))
for step in range(40):
F = { K:0 for (K,_) in D.items() }
for ((a,b),v) in E.items():
j = D[(a,b)]
F[(a,j)] += v
F[(j,b)] += v
E = F
#print(step+1,reprpairs(E))
from collections import defaultdict as dfd
S = dfd(int)
for ((a,b),v) in E.items():
S[a]+=v
S[b]+=v
S ={ k:(a+b) for (k,v) in S.items() for (a,b) in [divmod(v,2)] }
print(S, max(S.values())-min(S.values()))

9
d14/dograph.py Normal file
View File

@ -0,0 +1,9 @@
import sys
L = sys.stdin.read().splitlines()
L = L[2:]
L = [ l.split() for l in L ]
D = { tuple(k):v for [k,_,v] in L }
print('digraph G {')
for ((k,l),v) in D.items():
print(f'{k} -> {v} [label="{l}"];')
print("}")

102
d14/input Normal file
View File

@ -0,0 +1,102 @@
SVKVKCCBNHNSOSCCOPOC
BB -> O
BC -> F
BF -> O
BH -> O
BK -> B
BN -> F
BO -> S
BP -> O
BS -> O
BV -> O
CB -> V
CC -> K
CF -> N
CH -> C
CK -> K
CN -> P
CO -> H
CP -> O
CS -> P
CV -> V
FB -> H
FC -> F
FF -> V
FH -> N
FK -> N
FN -> P
FO -> V
FP -> B
FS -> V
FV -> K
HB -> B
HC -> S
HF -> P
HH -> B
HK -> S
HN -> V
HO -> V
HP -> O
HS -> B
HV -> H
KB -> C
KC -> C
KF -> B
KH -> B
KK -> B
KN -> H
KO -> S
KP -> S
KS -> N
KV -> K
NB -> P
NC -> S
NF -> H
NH -> B
NK -> N
NN -> K
NO -> N
NP -> B
NS -> P
NV -> F
OB -> V
OC -> V
OF -> H
OH -> C
OK -> O
ON -> P
OO -> V
OP -> F
OS -> H
OV -> F
PB -> H
PC -> B
PF -> P
PH -> K
PK -> F
PN -> B
PO -> N
PP -> V
PS -> S
PV -> B
SB -> C
SC -> C
SF -> K
SH -> S
SK -> H
SN -> P
SO -> C
SP -> P
SS -> K
SV -> B
VB -> S
VC -> P
VF -> S
VH -> V
VK -> S
VN -> V
VO -> N
VP -> F
VS -> S
VV -> O

18
d14/sample Normal file
View File

@ -0,0 +1,18 @@
NNCB
CH -> B
HH -> N
CB -> H
NH -> C
HB -> C
HC -> B
HN -> C
NN -> C
BH -> H
NC -> B
NB -> B
BN -> B
BB -> N
BC -> B
CC -> N
CN -> C