aboutsummaryrefslogtreecommitdiff
path: root/2020/16/puzzle-1.py
blob: f4343c8803dc0729a1e4f3b2bd41226e410c8bda (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
27
28
29
30
#!/usr/bin/env python3


def main() -> None:
	with open("input", "r") 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("-")))
			for j in range(bounds[0], bounds[1] + 1):
				valid.append(j)
		i += 1

	# Skip to nearby tickets
	i += 5
	acc = 0

	for j in range(i, len(data)):
		fields = tuple(map(int, data[j].split(",")))
		acc += sum(field for field in fields if field not in valid)

	print(acc)


if __name__ == "__main__":
	main()