Luna Lailatova
3 years ago
4 changed files with 244 additions and 0 deletions
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
from io import DEFAULT_BUFFER_SIZE |
||||
import sys |
||||
|
||||
poly = None |
||||
inserters = {} |
||||
|
||||
class polyme: |
||||
def __init__(self, initial): |
||||
self.Polymere = [] |
||||
self.letters = {} |
||||
self.dubles = {} |
||||
for f in initial: |
||||
self.Polymere.append(f) |
||||
for i in range(len(self.Polymere)): |
||||
if i != len(self.Polymere) - 1: |
||||
temp = self.Polymere[i] + self.Polymere[i + 1] |
||||
g = self.dubles.setdefault(temp, 0) |
||||
g += 1 |
||||
self.dubles.update({temp : g}) |
||||
temp2 = self.letters.setdefault(self.Polymere[i], 0) |
||||
temp2 += 1 |
||||
self.letters.update({self.Polymere[i] : temp2}) |
||||
print(self.letters, self.dubles, self.Polymere) |
||||
|
||||
def steppy(self): |
||||
tempdict = {} |
||||
tempdict.clear() |
||||
print(tempdict) |
||||
for key, insert in inserters.items(): |
||||
if key in self.dubles: |
||||
count = self.dubles[key] |
||||
if insert in self.letters: |
||||
adletters = self.letters[insert] |
||||
else: |
||||
adletters = 0 |
||||
adletters += count |
||||
self.letters.update({insert : adletters}) |
||||
dub1 = key[0] + insert |
||||
dub2 = insert + key[1] |
||||
g = tempdict.setdefault(dub1, 0) |
||||
g += count |
||||
tempdict.update({dub1 : g}) |
||||
g = tempdict.setdefault(dub2, 0) |
||||
g += count |
||||
tempdict.update({dub2 : g}) |
||||
g = tempdict.setdefault(key, 0) |
||||
g -= count |
||||
tempdict.update({key : g}) |
||||
for dub, amount in tempdict.items(): |
||||
g = self.dubles.setdefault(dub, 0) |
||||
g += amount |
||||
self.dubles.update({dub : g}) |
||||
print(self.letters, self.dubles, self.Polymere) |
||||
|
||||
|
||||
def findsolu(self): |
||||
temp = self.letters.values() |
||||
print(temp) |
||||
temp2 = max(temp) - min(temp) |
||||
return temp2 |
||||
|
||||
with open(sys.argv[1], 'r') as f: |
||||
for g in f.readlines(): |
||||
g = g.strip() |
||||
if poly is None: |
||||
poly = polyme(g) |
||||
continue |
||||
if g == '': |
||||
continue |
||||
else: |
||||
temp1, temp2 = g.split(' -> ') |
||||
inserters.update({temp1:temp2}) |
||||
|
||||
for i in range(40): |
||||
poly.steppy() |
||||
|
||||
print(poly.findsolu()) |
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
import sys |
||||
|
||||
poly = None |
||||
inserters = {} |
||||
|
||||
class polyme: |
||||
def __init__(self, initial): |
||||
self.Polymere = [] |
||||
for f in initial: |
||||
self.Polymere.append(f) |
||||
def steppy(self): |
||||
counter = 0 |
||||
temp = len(self.Polymere) - 1 |
||||
for i in range(temp): |
||||
active = self.Polymere[i + counter] + self.Polymere[i+1 + counter] |
||||
for key, insert in inserters.items(): |
||||
if active == key: |
||||
#print(key ,insert) |
||||
self.Polymere.insert(i + counter + 1, insert) |
||||
counter += 1 |
||||
def findsolu(self): |
||||
self.solution = {} |
||||
for f in self.Polymere: |
||||
g = self.solution.setdefault(f, 0) |
||||
g += 1 |
||||
self.solution.update({f : g}) |
||||
temp = self.solution.values() |
||||
print(temp) |
||||
temp2 = max(temp) - min(temp) |
||||
return temp2 |
||||
|
||||
with open(sys.argv[1], 'r') as f: |
||||
for g in f.readlines(): |
||||
g = g.strip() |
||||
if poly is None: |
||||
poly = polyme(g) |
||||
continue |
||||
if g == '': |
||||
continue |
||||
else: |
||||
temp1, temp2 = g.split(' -> ') |
||||
inserters.update({temp1:temp2}) |
||||
|
||||
for i in range(10): |
||||
poly.steppy() |
||||
|
||||
print(poly.findsolu()) |
@ -0,0 +1,102 @@
@@ -0,0 +1,102 @@
|
||||
VFHKKOKKCPBONFHNPHPN |
||||
|
||||
VS -> B |
||||
HK -> B |
||||
FO -> P |
||||
NC -> F |
||||
VN -> C |
||||
BS -> O |
||||
HS -> K |
||||
NS -> C |
||||
CV -> P |
||||
NV -> C |
||||
PH -> H |
||||
PB -> B |
||||
PK -> K |
||||
HF -> P |
||||
FV -> C |
||||
NN -> H |
||||
VO -> K |
||||
VP -> P |
||||
BC -> B |
||||
KK -> S |
||||
OK -> C |
||||
PN -> H |
||||
SB -> V |
||||
KO -> P |
||||
KH -> C |
||||
KS -> S |
||||
FP -> B |
||||
PV -> B |
||||
BO -> C |
||||
OS -> H |
||||
NB -> S |
||||
SP -> C |
||||
HN -> N |
||||
FN -> B |
||||
PO -> O |
||||
FS -> O |
||||
NH -> B |
||||
SO -> P |
||||
OB -> S |
||||
KC -> C |
||||
OO -> H |
||||
BB -> V |
||||
SC -> F |
||||
NP -> P |
||||
SH -> C |
||||
BH -> O |
||||
BP -> F |
||||
CC -> S |
||||
BN -> H |
||||
SS -> P |
||||
BF -> B |
||||
VK -> P |
||||
OV -> H |
||||
FC -> S |
||||
VB -> S |
||||
PF -> N |
||||
HH -> O |
||||
HC -> V |
||||
CH -> B |
||||
HP -> H |
||||
FF -> H |
||||
VF -> V |
||||
CS -> F |
||||
KP -> F |
||||
OP -> H |
||||
KF -> F |
||||
PP -> V |
||||
OC -> C |
||||
PS -> F |
||||
ON -> H |
||||
BK -> B |
||||
HV -> S |
||||
CO -> K |
||||
FH -> C |
||||
FB -> F |
||||
OF -> V |
||||
SN -> S |
||||
PC -> K |
||||
NF -> F |
||||
NK -> P |
||||
NO -> P |
||||
CP -> P |
||||
CK -> S |
||||
HB -> H |
||||
BV -> C |
||||
SF -> K |
||||
HO -> H |
||||
OH -> B |
||||
KV -> S |
||||
KN -> F |
||||
SK -> K |
||||
VH -> S |
||||
CN -> S |
||||
VC -> P |
||||
CB -> H |
||||
SV -> S |
||||
VV -> P |
||||
CF -> F |
||||
FK -> F |
||||
KB -> V |
Loading…
Reference in new issue