High-performance Sudoku library — solver (DLX + bitmask), generator, hints, difficulty grading. Pure TypeScript, zero dependencies.
npm install sudakuimport { Sudaku } from 'sudaku';
const sdk = new Sudaku();
// Solve
sdk.solve('530070000600195000098000060...');
// → { solved: true, solution: '534678912672195348...' }
// Generate
sdk.generate({ minClues: 25, symmetric: true });
// → { puzzle: '...', solution: '...' }
// Hint
sdk.hint('530070000...');
// → { found: true, hint: { technique: 'Hidden Single', explanation: '...' } }
// Difficulty
sdk.difficulty('530070000...');
// → { label: 'Easy', score: 5, techniquesUsed: ['Naked Single'], ... }| Feature | Method |
|---|---|
| Solve | solve(), solveBatch(), solveWithTimeout() |
| Logic Solve | solveLogic(), solveLogicSteps() (iterator) |
| Hints | hint(), allHints(), progressiveHint() |
| Difficulty | difficulty() — Easy → Evil, score 0-100 |
| Generate | generate(), generateBatch() with difficulty targeting |
| Validate | validate() — duplicates, solvability, uniqueness |
| Candidates | candidates(), candidateDigits() |
| Game State | createGame() → undo/redo, pencil marks, conflicts |
| Analysis | analyze() — symmetry, clue distribution, rating |
| Serialization | toSDK(), fromSDK(), toOpenSudoku(), prettyPrint() |
| Save/Load | saveGame(), loadGame() — JSON game state |
Naked Single → Hidden Single → Naked Pair → Hidden Pair → Naked Triple → Hidden Triple → Pointing Pair → Box/Line Reduction → X-Wing → Y-Wing → Unique Rectangle → Swordfish → Simple Coloring
Hybrid strategy — constraint propagation first, then:
- < 20 empties → Bitmask + MRV backtracking
- ≥ 20 empties → DLX (Dancing Links, Algorithm X)
~0.6ms per hard puzzle on modern hardware.
Strategy, Chain of Responsibility, Iterator, Observer, Command, Memento, Facade, Flyweight.
AGPL-3.0 — If you use this library, your project must also be open source under a compatible license.