2017 Day 13 Part 1
This commit is contained in:
parent
c282317273
commit
3421534adb
1 changed files with 29 additions and 0 deletions
29
2017/day13.py
Normal file
29
2017/day13.py
Normal 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))
|
||||||
Loading…
Reference in a new issue