mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Move 2015 out of the way.
This commit is contained in:
1
2015/day-12/input.txt
Normal file
1
2015/day-12/input.txt
Normal file
File diff suppressed because one or more lines are too long
24
2015/day-12/solution.py
Normal file
24
2015/day-12/solution.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from __future__ import print_function
|
||||
import fileinput
|
||||
import re
|
||||
import json
|
||||
|
||||
def totals(obj):
|
||||
if isinstance(obj, int):
|
||||
return obj
|
||||
if isinstance(obj, list):
|
||||
return sum(totals(i) for i in obj)
|
||||
if not isinstance(obj, dict) or "red" in list(obj.values()):
|
||||
return 0
|
||||
|
||||
return sum(totals(i) for i in list(obj.values()))
|
||||
|
||||
fileData = ''.join(line for line in fileinput.input())
|
||||
|
||||
# Solve the first part by regex, no parsing needed.
|
||||
pattern = re.compile(r"-?\d+")
|
||||
total = sum(int(match) for match in pattern.findall(fileData))
|
||||
|
||||
data = json.loads(fileData)
|
||||
|
||||
print(total, totals(data))
|
||||
Reference in New Issue
Block a user