Browse Source

Day 9.

master
Chris Smith 6 years ago
parent
commit
8db5f33c5e
2 changed files with 23 additions and 0 deletions
  1. 22
    0
      09.py
  2. 1
    0
      data/09.txt

+ 22
- 0
09.py View File

@@ -0,0 +1,22 @@
1
+with open('data/09.txt', 'r') as file:
2
+    garbage, escaped, depth, score, removed = False, False, 0, 0, 0
3
+    for char in file.readline():
4
+        if escaped:
5
+            escaped = False
6
+        elif garbage:
7
+            if char == '!':
8
+                escaped = True
9
+            elif char == '>':
10
+                garbage = False
11
+            else:
12
+                removed += 1
13
+        elif char == '<':
14
+            garbage = True
15
+        elif char == '{':
16
+            depth += 1
17
+            score += depth
18
+        elif char == '}':
19
+            depth -= 1
20
+
21
+print(f'Part one: {score}')
22
+print(f'Part two: {removed}')

+ 1
- 0
data/09.txt
File diff suppressed because it is too large
View File


Loading…
Cancel
Save