Sudoku Generator and Solver
Generate Sudoku puzzles at 4 difficulty levels and solve them instantly with a backtracking algorithm. Full keyboard support, pencil marks, and undo.
About
Sudoku solving reduces to an exact cover problem. A valid puzzle has exactly one solution derivable through constraint propagation across 27 groups (9 rows, 9 columns, 9 boxes). Generating a proper puzzle requires removing clues from a completed grid while verifying uniqueness at each step. If uniqueness is not enforced, the puzzle is ambiguous and therefore broken. This tool uses a backtracking solver with MRV (Minimum Remaining Values) heuristic to both generate guaranteed-unique puzzles and solve any valid board in milliseconds.
Difficulty is controlled by the number of given clues: Easy provides 38 - 45 clues, Medium 30 - 37, Hard 25 - 29, and Expert 22 - 24. The minimum number of clues for a unique Sudoku is 17, proven by McGuire et al. in 2012. This tool does not go below 22 to keep generation fast. Pencil marks (candidates) are supported for advanced solving techniques. Note: the auto-solver assumes a valid puzzle. Feeding it a board with contradictions will correctly report no solution.
Formulas
The backtracking solver operates on a constraint satisfaction model. For each empty cell, candidates are computed as:
Where Cr,c is the candidate set for row r, column c. Rr is the set of values already in row r. Colc is the set of values in column c. Bb is the set of values in box b. The box index is computed as:
The MRV heuristic selects the empty cell with the smallest |Cr,c| (fewest candidates) to minimize branching. If |Cr,c| = 0 for any empty cell, the branch is pruned (backtrack). If |Cr,c| = 1, the value is forced (naked single). Puzzle generation removes clues symmetrically and verifies uniqueness by confirming the solver finds exactly 1 solution.
Reference Data
| Difficulty | Given Clues | Avg. Solve Time (Human) | Techniques Required | Backtrack Steps (Solver) |
|---|---|---|---|---|
| Easy | 38 - 45 | 10 - 20 min | Naked Singles | < 50 |
| Medium | 30 - 37 | 20 - 40 min | Naked & Hidden Singles | 50 - 200 |
| Hard | 25 - 29 | 40 - 90 min | Pairs, Pointing, Box/Line | 200 - 1000 |
| Expert | 22 - 24 | 60 - 180 min | X-Wing, Swordfish, Chains | 1000+ |
| Minimum Possible | 17 | Hours to Days | All advanced + trial | 10000+ |
| Constraint Groups | ||||
| Rows | Each row must contain digits 1 - 9 exactly once | |||
| Columns | Each column must contain digits 1 - 9 exactly once | |||
| Boxes | Each 3ร3 box must contain digits 1 - 9 exactly once | |||
| Total Constraints | 27 groups ร 9 values = 243 binary constraints | |||
| Sudoku Mathematics | ||||
| Valid Completed Grids | 6,670,903,752,021,072,936,960 (Bertram Felgenhauer, 2005) | |||
| Essentially Different | 5,472,730,538 (after symmetry reduction) | |||
| Minimum Clue Puzzles | 49,151 known 17-clue puzzles catalogued | |||
| Search Space per Cell | Up to 9 candidates, reduced by constraints | |||
| Avg. Branching Factor | 2.5 - 4.0 for hard puzzles | |||