blob: b0d4bfd3d44d41db584d7dc1c48958159b18a3ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/usr/bin/env python3
from fileinput import input
lines = [[int(b) for b in line.strip()] for line in input()]
def jolt(bs: list[int], n: int) -> int:
if n == 1:
return max(bs)
n -= 1
b = max(bs[:-n])
i = bs.index(b)
return b * (10**n) + jolt(bs[i + 1 :], n)
silver = sum(jolt(bs, 2) for bs in lines)
gold = sum(jolt(bs, 12) for bs in lines)
print("silver:", silver)
print("gold:", gold)
|