38 lines
590 B
Python
38 lines
590 B
Python
import json
|
|
|
|
# Fill Input
|
|
|
|
try:
|
|
with open("12.txt", 'r', encoding='utf-8') as file:
|
|
input = json.load(file)
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
|
|
# Convert Corrdenate to string
|
|
|
|
def recursive_decend(json:any)->int:
|
|
match json:
|
|
case dict():
|
|
sum = 0;
|
|
for i in json:
|
|
""" Part 2
|
|
if json[i] == "red":
|
|
return 0
|
|
"""
|
|
|
|
sum += recursive_decend(json[i])
|
|
return sum
|
|
case list():
|
|
sum = 0;
|
|
for i in json:
|
|
sum += recursive_decend(i)
|
|
return sum
|
|
case int():
|
|
return json
|
|
case str():
|
|
return 0;
|
|
|
|
print(recursive_decend(input))
|
|
|
|
|