You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
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())
|
|
|