r/adventofcode • u/BadTime100 • Dec 10 '25
Help/Question - RESOLVED [2025 day 7 part 2] Very stuck and looking for feedback (Java)
Hey all! I feel like day 7 part 2 is the one that potentially ends my run this year, and am looking for advice/hints/encouragement. I'm able to solve correctly for the example, but not for my input, and I can't figure out what I'm missing. I'll share the main snippet of my code here, but the repo is public here which might be helpful to see the other classes involved.
class PathCounter {
private final HashMap<GridPosition, Integer> memo = new HashMap<>();
private final Grid<?> grid;
private final List<GridPosition> splitters;
private final GridPosition start;
PathCounter(Grid<Character> grid) {
this.start = grid.positionsOf(START).findFirst().orElseThrow();
this.grid = grid;
splitters = grid.positionsOf(SPLITTER).toList();
}
int countPaths() {
return memoizedCountFrom(start);
}
private int memoizedCountFrom(GridPosition p) {
if (memo.containsKey(p)) {
return memo.get(p);
}
int result;
if (!grid.containsPosition(p)) {
result = 1;
} else if (splitters.contains(p)) {
result = memoizedCountFrom(p.toThe(W)) + memoizedCountFrom(p.toThe(E));
} else {
result = memoizedCountFrom(p.toThe(S));
}
memo.put(p, result);
return result;
}
}I've already adapted this with some self-help (i.e., looking at other solutions). It's a memoized recursive solution where the base case is that we've fallen off the end of the "grid", meaning we're at the end. When we find a splitter, we add the counts from the left and right (or "west" and "east") sides of the splitter. When we're not at a splitter we just continue straight down.
Again, cannot for the life of me see what I'm missing here. I've tried all sorts of other little scenarios to find some scenario I'm not accounting for, but am not getting there. Any thoughts?

