Watch
1
0
Fork
You've already forked advent-of-code
0
advent-of-code/2017/day13.py
2026-07-31 16:28:58 -04:00

29 lines
580 B
Python

with open("input/day13.txt") as f:
input = f.read()
scanners = {}
for line in input.splitlines():
parts = line.split(": ")
d, r = int(parts[0]), int(parts[1])
assert d not in scanners, "no overlapping scanners"
scanners[d] = r
def part1(scanners):
severity = 0
for d in range(max(scanners.keys()) + 1):
r = scanners.get(d)
if r is None:
continue
assert r > 1, r
cycle = (r - 1) * 2
pos = d % cycle
if pos == 0:
severity += d * r
return severity
print(part1(scanners))