소스 검색

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
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


Loading…
취소
저장