Watch
1
0
Fork
You've already forked advent-of-code
0

2017 Day 13 Part 1

This commit is contained in:
Jeremy Kaplan 2026-07-31 16:28:58 -04:00
commit 3421534adb

29
2017/day13.py Normal file
View file

@ -0,0 +1,29 @@
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))