blob: f2c807d2df194c7cc6321d673ef1d8617d2d8228 (
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
|
#!/usr/bin/env python3
from fileinput import input
reports = [[int(level) for level in report.split()] for report in input()]
def incr(xs):
return all(x < y and y - x <= 3 for x, y in zip(xs, xs[1:]))
def safe(xs):
return incr(xs) or incr(xs[::-1])
def drops(xs):
return (xs[:idx] + xs[idx + 1 :] for idx, _ in enumerate(xs))
silver = sum(safe(rep) for rep in reports)
gold = sum(any(safe(mod) for mod in drops(rep)) for rep in reports)
print("silver:", silver)
print("gold:", gold)
|