소스 검색

Day 12

master
Chris Smith 8 년 전
부모
커밋
20ec9c8332
2개의 변경된 파일29개의 추가작업 그리고 0개의 파일을 삭제
  1. 28
    0
      12.py
  2. 1
    0
      12.txt

+ 28
- 0
12.py 파일 보기

@@ -0,0 +1,28 @@
1
+#!/usr/bin/python
2
+
3
+import json
4
+import re
5
+
6
+with open('12.txt', 'r') as file:
7
+    input = file.read()
8
+
9
+print("Part 1: %d" % sum(int(x) for x in re.findall('-?[0-9]+', input)))
10
+
11
+
12
+def process(obj):
13
+    if isinstance(obj, dict):
14
+        if 'red' in obj.values():
15
+            return 0
16
+        else:
17
+            return process(obj.values())
18
+
19
+    if isinstance(obj, list):
20
+        return sum(process(x) for x in obj)
21
+
22
+    if isinstance(obj, int):
23
+        return obj
24
+
25
+    return 0
26
+
27
+
28
+print("Part 2: %d" % process(json.loads(input)))

+ 1
- 0
12.txt
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


Loading…
취소
저장