parent
51a2205aa1
commit
c0b714acf8
3 changed files with 154 additions and 0 deletions
@ -0,0 +1,34 @@ |
||||
with open("input") as file: |
||||
startSequence = file.readline().rstrip("\n") |
||||
file.readline() |
||||
rulePairs = [line.split(" -> ") for line in file.read().splitlines()] |
||||
rules = {left: right for left, right in rulePairs} |
||||
|
||||
|
||||
def solve(sequence): |
||||
|
||||
pairCounts, elementCounts = {}, {} |
||||
|
||||
for a, b in zip(sequence, sequence[1:]): |
||||
pairCounts.setdefault(a + b, 0) |
||||
pairCounts[a + b] += 1 |
||||
|
||||
for a in sequence: |
||||
elementCounts.setdefault(a, 0) |
||||
elementCounts[a] += 1 |
||||
|
||||
for i in range(40): |
||||
for (a, b), count in pairCounts.copy().items(): |
||||
new = rules[a + b] |
||||
elementCounts.setdefault(new, 0) |
||||
elementCounts[new] += count |
||||
pairCounts.setdefault(a + new, 0) |
||||
pairCounts[a + new] += count |
||||
pairCounts.setdefault(new + b, 0) |
||||
pairCounts[new + b] += count |
||||
pairCounts[a + b] -= count |
||||
|
||||
return max(elementCounts.values()) - min(elementCounts.values()) |
||||
|
||||
|
||||
print(solve(startSequence)) |
@ -0,0 +1,102 @@ |
||||
KOKHCCHNKKFHBKVVHNPN |
||||
|
||||
BN -> C |
||||
OS -> K |
||||
BK -> C |
||||
KO -> V |
||||
HF -> K |
||||
PS -> B |
||||
OK -> C |
||||
OC -> B |
||||
FH -> K |
||||
NV -> F |
||||
HO -> H |
||||
KK -> H |
||||
CV -> P |
||||
SC -> C |
||||
FK -> N |
||||
VV -> F |
||||
FN -> F |
||||
KP -> O |
||||
SB -> O |
||||
KF -> B |
||||
CH -> K |
||||
VF -> K |
||||
BH -> H |
||||
KV -> F |
||||
CO -> N |
||||
PK -> N |
||||
NH -> P |
||||
NN -> C |
||||
PP -> H |
||||
SH -> N |
||||
VO -> O |
||||
NC -> F |
||||
BC -> B |
||||
HC -> H |
||||
FS -> C |
||||
PN -> F |
||||
CK -> K |
||||
CN -> V |
||||
HS -> S |
||||
CB -> N |
||||
OF -> B |
||||
OV -> K |
||||
SK -> S |
||||
HP -> C |
||||
SN -> P |
||||
SP -> B |
||||
BP -> C |
||||
VP -> C |
||||
BS -> K |
||||
FV -> F |
||||
PH -> P |
||||
FF -> P |
||||
VK -> F |
||||
BV -> S |
||||
VB -> S |
||||
BF -> O |
||||
BB -> H |
||||
OB -> B |
||||
VS -> P |
||||
KB -> P |
||||
SF -> N |
||||
PF -> S |
||||
HH -> P |
||||
KN -> K |
||||
PC -> B |
||||
NB -> O |
||||
VC -> P |
||||
PV -> H |
||||
KH -> O |
||||
OP -> O |
||||
NF -> K |
||||
HN -> P |
||||
FC -> H |
||||
PO -> B |
||||
OH -> C |
||||
ON -> N |
||||
VN -> B |
||||
VH -> F |
||||
FO -> B |
||||
FP -> B |
||||
BO -> H |
||||
CC -> P |
||||
CS -> K |
||||
NO -> V |
||||
CF -> N |
||||
PB -> H |
||||
KS -> P |
||||
HK -> S |
||||
HB -> K |
||||
HV -> O |
||||
SV -> H |
||||
CP -> S |
||||
NP -> N |
||||
FB -> B |
||||
KC -> V |
||||
NS -> P |
||||
OO -> V |
||||
SO -> O |
||||
NK -> K |
||||
SS -> H |
@ -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 |
Loading…
Reference in new issue