A typescript Sudoku package for generating, solving (step-by-step or all), and analyzing Sudoku boards with ease. Perfect for building Sudoku games and integrating Sudoku functionality into your applications.
Explore the docs »
View Demo
.
Report Bug
.
Request Feature
gzipped size: 3.2k
Key Features:
Board Generation: Quickly create Sudoku boards for various difficulty levels.
Solver: Solve Sudoku puzzles.
Step-by-Step Solution: Walk through the solution process step by step, making it ideal for educational purposes or enhancing user engagement in Sudoku apps.
Board Analysis: Analyze the difficulty and strategies to solve a sudoku board.
npm install sudoku-core@latest
function | Input | Output |
---|---|---|
generate | "easy" | "medium" | "hard" | "expert" | "master" | Board |
solve | Board | SolvingResult |
hint | Board | SolvingResult |
analyze | Board | AnalyzeData |
board:
// difficulty: easy - medium - hard - expert - master;
const board = generate("easy");
console.log(board);
[
1,
null,
9,
5,
8,
null,
null,
6,
3
//... 81 items
]
const solvedBoard = solve(board);
console.log(solvedBoard);
{
"solved": true,
"board": [
2,
7,
6,
3,
8,
1,
9
// ... 81 items
],
"steps": [
{
"strategy": "Single Candidate Strategy",
"updates": [{
"index": 5,
"filledValue": 1,
"eliminatedCandidate": null,
}],
"type": "value"
},
...steps
],
"analysis": {
"hasSolution": true,
"hasUniqueSolution": true,
"usedStrategies": [
{ "title": "Single Remaining Cell Strategy", "frequency": 21 },
...strategies
],
"difficulty": "master",
"score": 2232
}
}
const solvedBoard = hint(board);
console.log(solvedBoard);
{
"solved": true,
"board": [
null,
7,
6,
null,
null,
1, // null => 1
null
// ... 81 items
],
"steps": [
{
"strategy": "Single Candidate Strategy",
"updates": [{
"index": 5,
"filledValue": 1,
"eliminatedCandidate": null,
}],
"type": "value"
}
],
"analysis": {
"hasSolution": true,
"hasUniqueSolution": true,
"usedStrategies": [
{ "title": "Single Remaining Cell Strategy", "frequency": 21 },
...strategies
],
"difficulty": "master",
"score": 2232
}
}
const analyzeData = analyze(board);
console.log(analyzeData);
{
"hasSolution": true,
"hasUniqueSolution": true,
"usedStrategies": [
{ "title": "Single Remaining Cell Strategy", "frequency": 21 },
{ "title": "Single Candidate Cell Strategy", "frequency": 11 },
{ "title": "Single Candidate Value Strategy", "frequency": 29 },
{ "title": "Pointing Elimination Strategy", "frequency": 27 }
],
"level": "expert",
"score": 1683.1
}
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
git checkout -b feature/AmazingFeature
)git commit -m 'feat: Add some AmazingFeature'
)git push origin feature/AmazingFeature
)Distributed under the MIT License. See LICENSE for more information.