38 lines
869 B
Python
38 lines
869 B
Python
![]() |
#!/usr/bin/env python
|
||
|
|
||
|
def read_input():
|
||
|
with open('input.txt', 'r') as f:
|
||
|
data = f.read().splitlines()
|
||
|
return data[0]
|
||
|
|
||
|
def find_longest_match(polymer):
|
||
|
result = 1
|
||
|
for x in range(len(polymer)-1):
|
||
|
if abs(ord(polymer[x]) - ord(polymer[x+1])) != 32:
|
||
|
break
|
||
|
result += 1
|
||
|
return result
|
||
|
|
||
|
|
||
|
polymer = read_input()
|
||
|
parsing_pos = 0
|
||
|
|
||
|
while parsing_pos < len(polymer):
|
||
|
lm = find_longest_match(polymer[parsing_pos:])
|
||
|
if lm < 2:
|
||
|
parsing_pos += 1
|
||
|
continue
|
||
|
|
||
|
# print("found({}, {}) : {}".format(parsing_pos, lm, polymer[parsing_pos:parsing_pos+lm]))
|
||
|
|
||
|
lm = 2
|
||
|
if parsing_pos == 0:
|
||
|
polymer = polymer[lm:]
|
||
|
else:
|
||
|
polymer = polymer[:parsing_pos] + polymer[lm+parsing_pos:]
|
||
|
parsing_pos -= 1
|
||
|
|
||
|
# print("new polymer: {}".format(polymer))
|
||
|
|
||
|
print(len(polymer))
|