1
0
Fork 0

2015 day 12

This commit is contained in:
Lucidiot 2019-11-17 13:43:54 +01:00
parent 56fb20e704
commit 2b107ba91d
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
2 changed files with 35 additions and 0 deletions

16
2015/12/part1.py Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3
# jq --stream 'select(length >= 2)|.[1]|numbers' | paste -sd+ | bc -l
import json
import sys
total = 0
def int_sum(value):
global total
parsed = int(value)
total += parsed
return parsed
json.load(sys.stdin, parse_int=int_sum)
print(total)

19
2015/12/part2.py Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env python3
import json
import sys
def get_numbers(data):
if isinstance(data, int):
yield data
elif isinstance(data, dict):
if 'red' in data.keys() or 'red' in data.values():
return
for value in data.values():
yield from get_numbers(value)
elif isinstance(data, list):
for item in data:
yield from get_numbers(item)
print(sum(get_numbers(json.load(sys.stdin))))