-
Notifications
You must be signed in to change notification settings - Fork 0
/
day9.py
34 lines (28 loc) · 744 Bytes
/
day9.py
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
with open('day9-input.txt') as f:
input_stream = f.readline().strip()
total_score = 0
garbage_score = 0
current_nesting = 0
inside_garbage = False
skip_next = False
for token in input_stream:
if inside_garbage:
if skip_next:
skip_next = False
else:
if token == ">":
inside_garbage = False
elif token == "!":
skip_next = True
else:
garbage_score += 1
else:
if token == "<":
inside_garbage = True
if token == "{":
current_nesting += 1
if token == "}":
total_score += current_nesting
current_nesting -= 1
print(total_score)
print(garbage_score)