File tree Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Original file line number Diff line number Diff line change
1
+ 156366
2
+ 96852
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env python3
2
+
3
+ def load_data (filename ):
4
+ with open (filename , 'r' ) as f :
5
+ for line in f :
6
+ line = line .rstrip ('\n ' )
7
+ yield line
8
+
9
+ # Part One
10
+
11
+ from json import loads
12
+
13
+ text = next (load_data ('input.txt' ))
14
+ j = loads (text )
15
+
16
+ def jsum (j , ignore_red = False ):
17
+ if type (j ) is list :
18
+ return sum (jsum (a , ignore_red ) for a in j )
19
+ elif type (j ) is dict :
20
+ if ignore_red and "red" in j .values ():
21
+ return 0
22
+ return sum (jsum (a , ignore_red ) for a in j .values ())
23
+ elif type (j ) is int :
24
+ return j
25
+ return 0
26
+
27
+ print (jsum (j ))
28
+
29
+ # Part Two
30
+
31
+ print (jsum (j , True ))
Original file line number Diff line number Diff line change 1
1
```
2
2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
3
- 2015 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- +
3
+ 2015 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- +
4
4
2016 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -
5
5
2017 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -
6
6
2018 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- +
You can’t perform that action at this time.
0 commit comments