Solve 2015 days 11-14.

This commit is contained in:
2024-01-31 21:20:45 -05:00
parent 0dfb4f974a
commit 35a01f1f65
5 changed files with 169 additions and 1 deletions

27
2015/d12.py Normal file
View File

@@ -0,0 +1,27 @@
import json
data = open(0).read().strip()
part_2 = False
def addup(d):
r = 0
if isinstance(d, list):
for e in d:
v = addup(e)
if v is not None:
r += v
elif isinstance(d, dict):
for e in d.values():
v = addup(e)
if v is None:
return 0
r += v
elif isinstance(d, str):
if part_2 and d == "red":
return None
else:
r += d
return r
data = json.loads(data)
print(addup(data))