Chris Smith 6 gadus atpakaļ
vecāks
revīzija
8db5f33c5e
2 mainītis faili ar 23 papildinājumiem un 0 dzēšanām
  1. 22
    0
      09.py
  2. 1
    0
      data/09.txt

+ 22
- 0
09.py Parādīt failu

@@ -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
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


Notiek ielāde…
Atcelt
Saglabāt