-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09_code.py
More file actions
35 lines (31 loc) · 795 Bytes
/
Copy path09_code.py
File metadata and controls
35 lines (31 loc) · 795 Bytes
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
def stream_processing(stream):
score = 0
groups = 0
in_garbage = False
garbage_count = 0
i = 0
while i < len(stream):
if stream[i] == '!':
i += 2
continue
if in_garbage:
if stream[i] == '>':
in_garbage = False
else:
garbage_count += 1
elif stream[i] == '<':
in_garbage = True
elif stream[i] == '{':
groups += 1
elif stream[i] == '}':
score += groups
groups += -1
i += 1
# Part 1 answer
print 'Number of groups: ', score
# Part 2 answer
print 'Garbage removed: ', garbage_count
f = open('09_input.txt', 'r')
stream = f.readline()
# Part 1 and Part 2
stream_processing(stream)