blob: 4c16c6dff7d028138ae7657e5044bb2692611279 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#!/usr/bin/env python3
from fileinput import input
lines = [[int(b) for b in line.strip()] for line in input()]
def joltage(bs: list[int]):
d2 = max(bs[:-1])
return max(d2 * 10 + max(bs[idx + 1 :]) for idx, b in enumerate(bs[:-1]) if b == d2)
silver = sum(map(joltage, lines))
gold = 0
print("silver:", silver)
print("gold:", gold)
|