38 lines
744 B
Python
38 lines
744 B
Python
from lib import get_data
|
|
import json
|
|
|
|
data = get_data(__file__).strip()
|
|
|
|
o = json.loads(data)
|
|
|
|
|
|
def xsum(obj, part_2=False):
|
|
t = 0
|
|
if type(obj) is int:
|
|
t += obj
|
|
elif type(obj) is list:
|
|
for o in obj:
|
|
t += xsum(o, part_2)
|
|
elif type(obj) is dict:
|
|
if part_2:
|
|
st = 0
|
|
for o in obj.values():
|
|
st += xsum(o, part_2)
|
|
if type(o) is str and o == "red":
|
|
break
|
|
else:
|
|
t += st
|
|
else:
|
|
for o in obj.values():
|
|
t += xsum(o, part_2)
|
|
elif type(obj) is str:
|
|
pass
|
|
else:
|
|
print(obj)
|
|
assert False
|
|
return t
|
|
|
|
|
|
print(xsum(o))
|
|
print(xsum(o, True))
|