You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
829 B
Python

#!/usr/bin/env python3
with open('input.txt', 'r') as f:
polymer = f.read()
print('Polymer length:', len(polymer))
modifications = True
rounds = 0
while modifications:
modifications = False
rounds += 1
mods = 0
new_polymer = []
skip = False
for i, el in enumerate(polymer[:-1]):
if skip:
skip = False
continue
next_el = polymer[i + 1]
if el != next_el and el.upper() == next_el.upper():
modifications = True
mods += 1
skip = True
continue
new_polymer.append(el[-1])
if not skip:
new_polymer.append(polymer[-1])
polymer = ''.join(new_polymer)
print(f'Round: {rounds}. Modifications found: {mods}. Polymer length: {len(polymer)}')
print(polymer)
print(len(polymer))