Article

How a Computer Generates a Sudoku With Exactly One Solution

Published 2026-10-06

Two very different problems, solved back to back

Generating a Sudoku puzzle is really two separate problems stacked on top of each other: first, build any complete, valid, filled 9×9 grid; second, figure out which cells can be erased without the puzzle becoming either unsolvable or solvable in more than one way.

Step 1: filling the grid with backtracking

A filled grid is built one cell at a time: try placing a number, check it doesn't repeat in that row, column or 3×3 box, and move to the next cell. If a cell has no valid number left to try, the algorithm backtracks — undoing the last placement and trying a different number there instead. Shuffling the order numbers are tried in keeps every generated grid different, even though the underlying method is identical every time.

Step 2: erasing cells without breaking uniqueness

Starting from a full grid, cells are erased one at a time, in random order. After each erasure, the generator has to check: does the puzzle still have exactly one valid solution, or did removing that number open the door to a second valid way of filling the grid? Checking this means running a solver that counts solutions rather than just finding one, and stopping early the moment it finds a second valid solution.

Why that uniqueness check actually matters

A Sudoku with two or more valid solutions isn't really solvable by logic alone — a player following all the normal rules could correctly fill in every cell and still not match "the" answer, because there isn't a single answer. Skipping the uniqueness check is the shortcut some weaker generators take, and it's exactly what produces those frustrating puzzles that don't add up.

Why harder puzzles take more computation

The fewer starting numbers a puzzle has, the more candidate cells the generator has to test (and often reject) before it finds a combination that still has a unique solution, which is why generating a genuinely hard puzzle takes a little more processing than an easy one, even though both use the identical underlying algorithm.

Try it yourself

Our Sudoku tool generates a fresh puzzle this same way every time, at your choice of difficulty, with a guaranteed unique solution.

Ready to try it yourself?
Open the Sudoku →