-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5-1.py
More file actions
41 lines (36 loc) · 1.06 KB
/
Copy path5-1.py
File metadata and controls
41 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
input = []
with open('5_input.txt') as f:
for line in f:
input.append(line)
#input = [ 'dabAcCaCBAcCcaDA' ]
def makeReaction(input):
finished = False
while not finished:
for pos in range(len(input) - 1):
print('currently working on pos {0} / {1}. input: {2}'.format(pos, len(input), len(input)))
curr_letter = input[pos]
try:
next_letter = input[pos + 1]
except IndexError:
finished = True
if polyReact(curr_letter, next_letter):
new_input = input[:pos] + input[pos + 2:]
input = new_input
break
if pos + 2 == len(input):
finished = True
break
return input
def polyReact(a, b):
if a.islower():
if a.upper() == b:
return True
elif a.isupper():
if a.lower() == b:
return True
return False
if __name__ == '__main__':
input = input[0]
result = makeReaction(input)
print(len(result))