User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
Category Puzzles
Click "Generate Puzzle" or "Example" to start.
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

About

A correctly constructed Sudoku puzzle has exactly one valid solution. Generating such a puzzle requires two distinct phases: producing a complete Latin square that satisfies all row, column, and 3ร—3 box constraints, then strategically removing clues while verifying uniqueness after each removal via a constraint-propagation solver. Failure to enforce uniqueness yields an ambiguous grid - unsuitable for logical deduction and frustrating to solve. This generator implements recursive backtracking with randomized candidate selection for board construction and a dual-phase carving algorithm that checks solution count โ‰ค 1 at every step.

Difficulty is controlled by the number of revealed clues: Easy provides 36 - 45 clues, Medium 27 - 35, Hard 22 - 26, and Expert as few as 17 - 21. The minimum possible clue count for a unique 9ร—9 Sudoku is 17, proven by McGuire et al. in 2012. Note: Expert-level generation may take longer due to the exhaustive uniqueness verification required at low clue counts. The algorithm approximates difficulty by clue count alone - it does not analyze solving technique complexity (naked pairs, X-wings, etc.).

sudoku puzzle generator logic puzzle sudoku maker brain teaser number puzzle

Formulas

The Sudoku constraint can be expressed formally. Let S be the set of cells indexed r, c โˆˆ {0, โ€ฆ, 8}. Each cell holds a value v(r, c) โˆˆ {1, โ€ฆ, 9}. The puzzle is valid when three uniqueness constraints hold simultaneously:

Row constraint: โˆ€ r : |{ v(r, c) : c โˆˆ 0..8 }| = 9
Column constraint: โˆ€ c : |{ v(r, c) : r โˆˆ 0..8 }| = 9
Box constraint: โˆ€ br, bc โˆˆ {0,1,2} : |{ v(3br + i, 3bc + j) : i,j โˆˆ 0..2 }| = 9

The box index for cell (r, c) is computed as:

box = 3 โ‹… floor(r รท 3) + floor(c รท 3)

Where r = row index (0 - 8), c = column index (0 - 8), v(r,c) = digit placed in that cell, br and bc = box row and column indices. The generation algorithm fills cells using backtracking with time complexity O(9n) worst-case, where n = empty cells, though constraint propagation prunes this dramatically in practice.

Reference Data

DifficultyClues GivenEmpty CellsApprox. Generation TimeTypical Solving Time (Human)Techniques Required
Easy36-4536-45< 200 ms5-15 minNaked Singles
Medium27-3546-54< 500 ms15-30 minNaked & Hidden Singles
Hard22-2655-59< 1 s30-60 minPairs, Pointing, Box/Line
Expert17-2160-641-5 s1-3 hrX-Wing, Swordfish, Chains
Sudoku Grid Constants
Grid Size9 ร— 9 = 81 cells
Sub-boxes9 boxes of 3 ร— 3
Total Valid Completed Grids6,670,903,752,021,072,936,960 (≈ 6.67 ร— 1021)
Min Clues for Uniqueness17 (proven 2012, McGuire - Tugemann - Civario)
Known 17-clue Puzzles≈ 49,000 catalogued
Digits Used1 through 9 (0 not used)
Constraint Groups27 (9 rows + 9 columns + 9 boxes)
Cells per Group9
Peers per Cell20 (shared row + column + box, minus self, minus duplicates)
Symmetry TypesRotational (180ยฐ), Diagonal, Full (4-fold), None

Frequently Asked Questions

After constructing a fully solved board, the algorithm removes clues one at a time in randomized order. After each removal, a constraint-propagation solver runs to count solutions. If the solver finds more than one valid completion, the clue is restored. This process continues until the target clue count is reached or no further cells can be safely removed. The solver uses naked singles and hidden singles for propagation, falling back to recursive backtracking when needed, counting up to 2 solutions before stopping.
Expert puzzles require only 17-21 clues out of 81 cells. At each removal step, the uniqueness solver must verify the entire remaining grid has exactly one solution. With fewer clues, the solver's search space grows exponentially. Additionally, many removal attempts at low clue counts fail the uniqueness check, requiring the algorithm to try different cells. The theoretical minimum of 17 clues is especially expensive to reach and is not guaranteed on every attempt.
No. Clue count is a rough proxy. True difficulty depends on which solving techniques are required: a 25-clue puzzle solvable entirely with naked singles is easier than a 28-clue puzzle requiring X-Wing or Swordfish patterns. This generator uses clue count as the primary difficulty metric. For competition-grade difficulty grading, technique-aware analysis (checking for required use of pairs, triples, coloring, etc.) would be needed.
No. In 2012, McGuire, Tugemann, and Civario proved through exhaustive computational search that no 9ร—9 Sudoku puzzle with 16 or fewer clues can have a unique solution. The proof required over 7 million CPU-hours. There are approximately 49,000 known distinct 17-clue puzzles.
No. The print stylesheet hides all UI controls, the solution toggle, and difficulty selectors. Only the puzzle grid with given clues prints, formatted for A4 paper with clear sub-box borders. You can reveal and print the solution separately by toggling "Show Solution" before printing.
Each cell has exactly 20 peers: 8 other cells in its row, 8 in its column, and 8 in its 3ร—3 box, minus the 4 cells counted twice (shared row-box or column-box intersections). When placing digit v in a cell, all 20 peers are checked for conflicts. This peer count is constant and independent of puzzle state, making constraint checking O(1) per cell.