Skip to content

Commit 2e02de4

Browse files
committed
added 2015/day12
1 parent 425554f commit 2e02de4

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

2015/day12/answers.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
156366
2+
96852

2015/day12/input.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

2015/day12/run.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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))

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
```
22
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 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- +
44
2016 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -
55
2017 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -
66
2018 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- +

0 commit comments

Comments
 (0)