My Advent of Code solutions in Python.
kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code
python
1import fileinput
2
3score = 0
4depth = 0
5garb_chars = 0
6
7in_garbage = False
8skip = False
9
10for c in fileinput.input()[0].strip():
11 if skip:
12 skip = False
13
14 elif c == '!':
15 skip = True
16
17 elif in_garbage:
18 if c == '>':
19 in_garbage = False
20 else:
21 garb_chars += 1
22
23 else:
24 if c == '{':
25 depth += 1
26 elif c == '}':
27 score += depth
28 depth -= 1
29 elif c == '<':
30 in_garbage = True
31
32print "Total score for all groups:", score
33print "Non-canceled garbage characters:", garb_chars