Menu

Designing a sudoku variant: the part that is actually hard is the rule check
📰

Designing a sudoku variant: the part that is actually hard is the rule check

DEV Community: javascript·Leo Wong·8 days ago
#xytXTygl
#devtojavascript#devto#dev#rule#solver
Long article (507 words) — no AI summary yet.
Reading 0:00
15s threshold

Everyone assumes the hard part of a puzzle generator is the solving algorithm. It is not. The hard part is proving that the puzzle you generated has exactly one solution - and that gets dramatically harder once you add a second rule family on top of the standard one.

I have been building a variant called Queens and Star, which layers two extra constraints onto a grid: region markers and a small set of starred cells that must obey their own counting rule. Here is what that taught me about generator design.

Rule check first, solver second

The temptation is to write a solver and let it treat the extra rules as optional decorations. That fails fast, because a solver that ignores a rule will happily certify a grid as valid when it is not.

The order that works:

Write an incremental rule checker that validates each placement against every rule family at once.

Make the solver call that checker and nothing else, so there is exactly one definition of valid.

Count solutions with a hard stop at two.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.