summaryrefslogtreecommitdiffstats
path: root/12/solution.py
blob: f4162fb93794a1af45523c4309ec6f43828125b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from json import load

def part1(data) -> int:
    if type(data) is list:
        return sum(part1(d) for d in data)
    elif type(data) is dict:
        return sum(part1(v) for k, v in data.items())
    if type(data) is int:
        return data
    return 0

def part2(data) -> int:
    if type(data) is list:
        return sum(part2(d) for d in data)
    elif type(data) is dict and 'red' not in data.values():
        return sum(part2(v) for k, v in data.items())
    if type(data) is int:
        return data
    return 0

if __name__ == '__main__':
    with open('input') as f:
        d = load(f)
    print(part1(d))
    print(part2(d))