浏览代码

Day 9.

master
Chris Smith 6 年前
父节点
当前提交
8db5f33c5e
共有 2 个文件被更改,包括 23 次插入0 次删除
  1. 22
    0
      09.py
  2. 1
    0
      data/09.txt

+ 22
- 0
09.py 查看文件

@@ -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
文件差异内容过多而无法显示
查看文件


正在加载...
取消
保存