A Sudoku puzzle generator & solver JavaScript library
sudoku.js is a compact JavaScript library for generating and solving
9×9 Sudoku puzzles.
It is fully browser-compatible and can also be imported in Node.js or
bundlers.
The puzzle generator uses constraint propagation + randomization to produce boards at various difficulties, while the solver guarantees a valid solution using depth-first search with constraint logic.
- ✔️ Generate playable Sudoku puzzles\
- ✔️ Choose difficulty: easy, medium, expert, master, extreme\
- ✔️ Solve any valid puzzle automatically\
- ✔️ Zero dependencies\
- ✔️ Works in browser and Node.js\
- ✔️ Lightweight & simple to integrate
npm i @acrazypie/sudoku.js<script src="path/to/sudoku.js"></script>
<script>
const puzzle = sudoku.generate("medium");
</script>import sudoku from "@acrazypie/sudoku.js";
const puzzle = sudoku.generate("expert");
console.log(puzzle);const solved = sudoku.solve(puzzle);
console.log(solved);const valid = sudoku.validate_board(puzzle);
console.log(valid);Generate a Sudoku puzzle.
Returns an 81-character string, using "." for empty cells.
Name Approx. clues
easy ~62 medium ~52 expert ~42 master ~32 extreme ~22
Solves a given Sudoku board.
Returns the solution string, or false if unsolvable.
Checks board format (length, characters).
Returns true or an error message.
- Rewrite generator to use logic-based methods\
- Guarantee unique-solution puzzles\
- Add proper logical hints\
- Add difficulty grading\
- Improve performance & seeding
- Fork → modify → PR\
- Write tests\
- Follow project style\
- Report bugs & issues
MIT License --- see the LICENSE file.
This project follows the
Contributor Covenant Code of
Conduct.
View changelog HERE