2022 begins.
This commit is contained in:
102
2021/14/data
Normal file
102
2021/14/data
Normal file
@@ -0,0 +1,102 @@
|
||||
ONHOOSCKBSVHBNKFKSBK
|
||||
|
||||
HO -> B
|
||||
KB -> O
|
||||
PV -> B
|
||||
BV -> C
|
||||
HK -> N
|
||||
FK -> H
|
||||
NV -> C
|
||||
PF -> K
|
||||
FV -> B
|
||||
NH -> P
|
||||
CO -> N
|
||||
HV -> P
|
||||
OH -> H
|
||||
BC -> H
|
||||
SP -> C
|
||||
OK -> F
|
||||
KH -> N
|
||||
HB -> V
|
||||
FP -> N
|
||||
KP -> O
|
||||
FB -> O
|
||||
FH -> F
|
||||
CN -> K
|
||||
BP -> P
|
||||
SF -> O
|
||||
CK -> K
|
||||
KN -> O
|
||||
VK -> C
|
||||
HP -> N
|
||||
KK -> V
|
||||
KO -> C
|
||||
OO -> P
|
||||
BH -> B
|
||||
OC -> O
|
||||
HC -> V
|
||||
HS -> O
|
||||
SH -> V
|
||||
SO -> C
|
||||
FS -> N
|
||||
CH -> O
|
||||
PC -> O
|
||||
FC -> S
|
||||
VO -> H
|
||||
NS -> H
|
||||
PH -> C
|
||||
SS -> F
|
||||
BN -> B
|
||||
BF -> F
|
||||
NC -> F
|
||||
CS -> F
|
||||
NN -> O
|
||||
FF -> P
|
||||
OF -> H
|
||||
NF -> O
|
||||
SC -> F
|
||||
KC -> F
|
||||
CP -> H
|
||||
CF -> K
|
||||
BS -> S
|
||||
HN -> K
|
||||
CB -> P
|
||||
PB -> V
|
||||
VP -> C
|
||||
OS -> C
|
||||
FN -> B
|
||||
NB -> V
|
||||
BB -> C
|
||||
BK -> V
|
||||
VF -> V
|
||||
VC -> O
|
||||
NO -> K
|
||||
KF -> P
|
||||
FO -> C
|
||||
OB -> K
|
||||
ON -> S
|
||||
BO -> V
|
||||
KV -> H
|
||||
CC -> O
|
||||
HF -> N
|
||||
VS -> S
|
||||
PN -> P
|
||||
SK -> F
|
||||
PO -> V
|
||||
HH -> F
|
||||
VV -> N
|
||||
VH -> N
|
||||
SV -> S
|
||||
CV -> B
|
||||
KS -> K
|
||||
PS -> V
|
||||
OV -> S
|
||||
SB -> V
|
||||
NP -> K
|
||||
SN -> C
|
||||
NK -> O
|
||||
PK -> F
|
||||
VN -> P
|
||||
PP -> K
|
||||
VB -> C
|
||||
OP -> P
|
18
2021/14/example_data
Normal file
18
2021/14/example_data
Normal 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
|
45
2021/14/main.py
Normal file
45
2021/14/main.py
Normal file
@@ -0,0 +1,45 @@
|
||||
str = ''
|
||||
data = {}
|
||||
letters = []
|
||||
with open('data', 'r') as fp:
|
||||
for line in fp:
|
||||
if(' -> ' in line):
|
||||
pair = line.strip().split(' -> ')
|
||||
data[pair[0]] = pair[1]
|
||||
elif(len(line) > 1):
|
||||
str = line.strip()
|
||||
|
||||
for ch in str:
|
||||
if(not ch in letters):
|
||||
letters.append(ch)
|
||||
letters.sort()
|
||||
|
||||
# # DEBUG(dev):
|
||||
# print(data)
|
||||
# print(str)
|
||||
# print(letters)
|
||||
|
||||
for step in range(0, 40):
|
||||
print('BEFORE:', str)
|
||||
new_str = ''
|
||||
for i in range(0, len(str) - 1):
|
||||
lookup = str[i:i+2]
|
||||
print(lookup)
|
||||
if(lookup in data.keys()):
|
||||
new_str += str[i] + data[lookup]
|
||||
else:
|
||||
new_str += str[i]
|
||||
new_str += str[-1]
|
||||
str = new_str
|
||||
|
||||
counts = {}
|
||||
for ch in str:
|
||||
if(ch in counts):
|
||||
counts[ch] += 1
|
||||
else:
|
||||
counts[ch] = 1
|
||||
|
||||
counts_list = list(counts.values())
|
||||
counts_list.sort()
|
||||
|
||||
print(counts_list[-1] - counts_list[0])
|
45
2021/14/main2.py
Normal file
45
2021/14/main2.py
Normal file
@@ -0,0 +1,45 @@
|
||||
str = ''
|
||||
data = {}
|
||||
letters = []
|
||||
with open('data', 'r') as fp:
|
||||
for line in fp:
|
||||
if(' -> ' in line):
|
||||
pair = line.strip().split(' -> ')
|
||||
data[pair[0]] = pair[1]
|
||||
elif(len(line) > 1):
|
||||
str = line.strip()
|
||||
|
||||
for ch in str:
|
||||
if(not ch in letters):
|
||||
letters.append(ch)
|
||||
letters.sort()
|
||||
|
||||
# # DEBUG(dev):
|
||||
# print(data)
|
||||
# print(str)
|
||||
# print(letters)
|
||||
|
||||
for step in range(0, 40):
|
||||
new_str = ''
|
||||
for i in range(0, len(str) - 1):
|
||||
lookup = str[i:i+2]
|
||||
if(lookup in data.keys()):
|
||||
new_str += str[i] + data[lookup]
|
||||
else:
|
||||
new_str += str[i]
|
||||
new_str += str[-1]
|
||||
str = new_str
|
||||
print('Step ', step+1, ', length', len(str))
|
||||
|
||||
# NOTE(dev): un-indent this (take it out of the for loop) for just a final answer
|
||||
counts = {}
|
||||
for ch in str:
|
||||
if(ch in counts):
|
||||
counts[ch] += 1
|
||||
else:
|
||||
counts[ch] = 1
|
||||
|
||||
counts_list = list(counts.values())
|
||||
counts_list.sort()
|
||||
|
||||
print(counts_list, counts_list[-1] - counts_list[0])
|
Reference in New Issue
Block a user