File tree Expand file tree Collapse file tree 5 files changed +179
-0
lines changed
Expand file tree Collapse file tree 5 files changed +179
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ from puzzle import readInput
4+ from collections import Counter
5+
6+
7+ if __name__ == '__main__' :
8+ template , moves = readInput ()
9+
10+ for _ in range (10 ):
11+ result = ''
12+ for index in range (len (template ) - 1 ):
13+ result += template [index ] + moves [template [index :index + 2 ]]
14+ template = result + template [- 1 ]
15+
16+ m = Counter (template ).most_common ()
17+ print (m [0 ][1 ] - m [- 1 ][1 ])
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ from puzzle import readInput
4+ from collections import defaultdict
5+
6+
7+ if __name__ == '__main__' :
8+ template , moves = readInput ()
9+
10+ counts = defaultdict (int )
11+ for index in range (len (template ) - 1 ):
12+ counts [template [index :index + 2 ]] += 1
13+
14+ for _ in range (40 ):
15+ nextCounts = defaultdict (int )
16+ for key , count in counts .items ():
17+ move = moves [key ]
18+ nextCounts [key [0 ] + move ] += count
19+ nextCounts [move + key [1 ]] += count
20+ counts = nextCounts
21+
22+ letters = defaultdict (int )
23+ for key , count in counts .items ():
24+ letters [key [0 ]] += count
25+ letters [template [- 1 ]] += 1
26+
27+ s = sorted (letters , key = lambda x : letters [x ])
28+
29+ print (letters [s [- 1 ]] - letters [s [0 ]])
Original file line number Diff line number Diff line change 1+ KOKHCCHNKKFHBKVVHNPN
2+
3+ BN -> C
4+ OS -> K
5+ BK -> C
6+ KO -> V
7+ HF -> K
8+ PS -> B
9+ OK -> C
10+ OC -> B
11+ FH -> K
12+ NV -> F
13+ HO -> H
14+ KK -> H
15+ CV -> P
16+ SC -> C
17+ FK -> N
18+ VV -> F
19+ FN -> F
20+ KP -> O
21+ SB -> O
22+ KF -> B
23+ CH -> K
24+ VF -> K
25+ BH -> H
26+ KV -> F
27+ CO -> N
28+ PK -> N
29+ NH -> P
30+ NN -> C
31+ PP -> H
32+ SH -> N
33+ VO -> O
34+ NC -> F
35+ BC -> B
36+ HC -> H
37+ FS -> C
38+ PN -> F
39+ CK -> K
40+ CN -> V
41+ HS -> S
42+ CB -> N
43+ OF -> B
44+ OV -> K
45+ SK -> S
46+ HP -> C
47+ SN -> P
48+ SP -> B
49+ BP -> C
50+ VP -> C
51+ BS -> K
52+ FV -> F
53+ PH -> P
54+ FF -> P
55+ VK -> F
56+ BV -> S
57+ VB -> S
58+ BF -> O
59+ BB -> H
60+ OB -> B
61+ VS -> P
62+ KB -> P
63+ SF -> N
64+ PF -> S
65+ HH -> P
66+ KN -> K
67+ PC -> B
68+ NB -> O
69+ VC -> P
70+ PV -> H
71+ KH -> O
72+ OP -> O
73+ NF -> K
74+ HN -> P
75+ FC -> H
76+ PO -> B
77+ OH -> C
78+ ON -> N
79+ VN -> B
80+ VH -> F
81+ FO -> B
82+ FP -> B
83+ BO -> H
84+ CC -> P
85+ CS -> K
86+ NO -> V
87+ CF -> N
88+ PB -> H
89+ KS -> P
90+ HK -> S
91+ HB -> K
92+ HV -> O
93+ SV -> H
94+ CP -> S
95+ NP -> N
96+ FB -> B
97+ KC -> V
98+ NS -> P
99+ OO -> V
100+ SO -> O
101+ NK -> K
102+ SS -> H
Original file line number Diff line number Diff line change 1+ import sys
2+
3+
4+ def readInput ():
5+ template = next (sys .stdin ).rstrip ()
6+ next (sys .stdin )
7+ points = {}
8+ for line in sys .stdin :
9+ from_ , to = line .rstrip ().split (' -> ' )
10+ assert from_ not in points
11+ points [from_ ] = to
12+
13+ return template , points
Original file line number Diff line number Diff line change 1+ NNCB
2+
3+ CH -> B
4+ HH -> N
5+ CB -> H
6+ NH -> C
7+ HB -> C
8+ HC -> B
9+ HN -> C
10+ NN -> C
11+ BH -> H
12+ NC -> B
13+ NB -> B
14+ BN -> B
15+ BB -> N
16+ BC -> B
17+ CC -> N
18+ CN -> C
You can’t perform that action at this time.
0 commit comments