8000 Part 2 test may fail, but takes too long anyway :-( · dumbledad/adventofcode@b8d641a · GitHub
[go: up one dir, main page]

Skip to content

Commit b8d641a

Browse files
author
Tim Regan
committed
Part 2 test may fail, but takes too long anyway :-(
1 parent c6b3f7e commit b8d641a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

2022/day15.py

Lines changed: 10 additions & 5 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ def distress_tuning(self, min=0, max=4_000_000):
4949
elif (sensor['closest_beacon'][1] in possible) and (sensor['closest_beacon'][0] in possible[sensor['closest_beacon'][1]]):
5050
possible[sensor['closest_beacon'][1]].pop(sensor['closest_beacon'][0])
5151
while True:
52-
first_y = next(iter(possible.keys()))
53-
if len(possible) == 1 and len(possible[first_y]) == 1:
54-
return (next(iter(possible[first_y])) * 4_000_000) + first_y
55-
56-
52+
y = next(iter(possible.keys()))
53+
x = next(iter(possible[y]))
54+
if len(possible) == 1 and len(possible[y]) == 1:
55+
return (x * 4_000_000) + y
56+
for sensor in self.sensors:
57+
if ((abs(sensor['coords'][0] - x) + abs(sensor['coords'][1] - y)) <= sensor['distance']
58+
and ((x, y) not in [s['coords'] for s in self.sensors])
59+
and ((x, y) not in [s['closest_beacon'] for s in self.sensors])):
60+
possible[y].pop(x, None)
61+
5762

5863

5964
def main():

2022/test_day15.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ def test_init():
1414
def test_impossible_count():
1515
tunnels = Tunnels(filename)
1616
assert tunnels.impossible_count(10) == 26
17+
18+
def test_distress_tuning():
19+
tunnels = Tunnels(filename)
20+
assert tunnels.distress_tuning() == 56_000_011

0 commit comments

Comments
 (0)
0