Skip to content

Commit 4a1ac51

Browse files
committed
Day 18 part 2 cleanup binary search
1 parent 6956fba commit 4a1ac51

File tree

1 file changed

+3
-3
lines changed
  • src/main/kotlin/com/cluddles/aoc/y2024

1 file changed

+3
-3
lines changed

src/main/kotlin/com/cluddles/aoc/y2024/Day18.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ object Day18: Solver<Grid<Int>, String> {
7373
val current = (min + max) / 2
7474
val valid = (solvePart1(input, current) != Int.MAX_VALUE)
7575
if (valid) {
76-
min = maxOf(current, min + 1)
76+
min = current
7777
} else {
78-
max = minOf(current, max - 1)
78+
max = current
7979
}
8080
}
81-
return with (input.iterableWithPos().first { it.data == max-1 }) { "$x,$y" }
81+
return with (input.iterableWithPos().first { it.data == min }) { "$x,$y" }
8282
}
8383

8484
}

0 commit comments

Comments
 (0)