Hacker News new | ask | show | jobs
by jsnell 2833 days ago
If the goal is puzzle generation, a backtracking solver is the wrong tool. When it comes to logic puzzles of this sort (Sudoku, Nonograms, etc) people don't like backtracking. There's often even an explicit promise that the puzzles can be solved with "just logic, no guessing needed".

So what you want is a solver that uses only the kinds of (usually local) reasoning that a human would use. I don't have examples handy for Sudoku, but for Nonograms it would be things like this: https://webpbn.com/solving.html

An added benefit is that this allows you to figure out how difficult the puzzle is to solve. What forms of reasoning are needed? How many squares are solvable at any one time? A backtracking solver, especially one that doesn't use any sort of heuristics, can't give that.

2 comments

For my site I use a backtracker to find a large number of single solution puzzles (rather fast). Those are used as a test base for my "human" solver (pretty slow), which are used for scoring and difficulty levels. I find that it's a nice balance.
Unless the problem space allows you to keep searching after a solution and discard it if a second one is found.

Heuristics are fast and natural, but hard to get right. They're handy to constrain the problem space though, but I would still apply backtracking just in case there's a valid single solution.