|
@@ -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)))
|