Skip to content

Commit

Permalink
:( real solution to day 17 :'(
Browse files Browse the repository at this point in the history
so it turns out I was just lucky :(

There is a requirement: *the ultra cart must go _at least 4 blocks_
before it can turn _or stop_* I was not filtering for this, but my
solution was working for the input anyways.

Reading discussions on reddit made me realize, I should add 1 more tests
to my solution. I am sad now...
  • Loading branch information
zebalu committed Dec 17, 2023
1 parent 1cad600 commit 725fa43
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public static void main(String[] args) {
}

private static int part1(List<String> maze) {
return minHeatLoss(maze, 3, (a, b) -> true);
return minHeatLoss(maze, 3, (a, b) -> true, i -> true);
}

private static int part2(List<String> maze) {
return minHeatLoss(maze, 10, (c, s) -> 4 <= s.straightLength() || s.pos().directionOf(c) == s.dir());
return minHeatLoss(maze, 10, (c, s) -> 4 <= s.straightLength() || s.pos().directionOf(c) == s.dir(), i -> 4<= i);
}

private static int minHeatLoss(List<String> maze, int maxLength, BiPredicate<Coord, State> nextFilter) {
private static int minHeatLoss(List<String> maze, int maxLength, BiPredicate<Coord, State> nextFilter, Predicate<Integer> stopFilter) {
int height = maze.size();
int width = maze.getFirst().length();
Predicate<Coord> isValidCood = c -> 0 <= c.x() && 0 <= c.y() && c.x < width && c.y < height;
Expand All @@ -36,7 +36,7 @@ private static int minHeatLoss(List<String> maze, int maxLength, BiPredicate<Coo
curr.nextStraight(c), curr.heatLoss() + heatCost(c, maze), curr.pos().directionOf(c)))
.filter(isValidState).toList();
for (State s : nextStates) {
if (s.pos().equals(target)) {
if (s.pos().equals(target) && stopFilter.test(s.straightLength())) {
return s.heatLoss;
}
var costKey = s.toKey();
Expand Down

0 comments on commit 725fa43

Please sign in to comment.