Hacker News new | past | comments | ask | show | jobs | submit login

Here you can apply the most common technique for such problems, which is to create a graph whose vertices are pairs made of a vertex of the original graph, plus the "state" of the traversal (or in other words, the essential information about the path used to reach the vertex).

In this case, the state is the number of walls passed, so just create a graph made of (v, k) pairs where for adjacent v and w in the grid, (v, k) connects to (w, k) if there is no wall, and it connects to (w, k + 1) if there is a wall.

Then run A*, finding the shortest path from (start, 0) to (end, 1), reconstruct the path and look at where it transitions from a (v, 0) to a (w, 1) and then return the wall between v and w.

You can use this for all sorts of other constraints, like finding a path that only changes direction up to N times, or a path where you don't get eaten by the monster moving deterministically (in this case the state is the monster position), or a path where you spend up to N time underwater consecutively, etc.

But GPT-4 seems very bad at solving problems, so even though this is an easy problem, it's not unexpected that it would not come up with this solution.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: