blob: c7cba379ebab875d582b121035177cb0741e679a (
plain) (
blame)
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
26
|
#!/usr/bin/env python3
def main() -> None:
with open("input", "r", encoding="utf-8") as f:
data = f.readlines()
i = 0
valid: list[int] = []
while data[i] != "\n":
ranges = data[i].split(": ")[1].split(" or ")
for _range in ranges:
bounds = tuple(map(int, _range.split("-")))
valid.extend(range(bounds[0], bounds[1] + 1))
i += 1
print(
sum(
sum(field for field in tuple(map(int, data[j].split(","))) if field not in valid)
for j in range(i + 5, len(data))
)
)
if __name__ == "__main__":
main()
|