sudoku-pro 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +6 -3
- package/sudoku-pro.js +25 -12
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sudoku-pro",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "sudoku-pro humbly presents itself as your go-to toolkit for generating, solving, and printing Sudoku puzzles spanning different difficulty levels. Powered by the reliable backtracking algorithm, it aspires to offer enthusiasts and learners alike a simple yet effective platform to engage with Sudoku puzzles. With Sudoku-Pro, embark on a journey of brain-teasing challenges or delve into educational endeavors with ease. This humble interface aims to make Sudoku puzzle creation and enjoyment accessible to all, ensuring a delightful experience for users of varying skill levels. Join us in exploring the possibilities of Sudoku puzzles while we humbly accompany you on your puzzle-solving adventures.",
|
|
5
5
|
"changelog": {
|
|
6
6
|
"1.0.6": "generateSudoku, printSudoku, solveSudoku",
|
|
7
7
|
"1.0.7": "getHint function added",
|
|
8
|
-
"1.0.
|
|
8
|
+
"1.0.8": "fixed the bug which cause issue while generating hard sudoku",
|
|
9
|
+
"1.0.10": "streamlined the code with concise logic, added very hard sudoku level"
|
|
9
10
|
},
|
|
10
11
|
"main": "sudoku-pro.js",
|
|
11
12
|
"repository": {
|
|
@@ -15,7 +16,8 @@
|
|
|
15
16
|
"scripts": {
|
|
16
17
|
"easy": "node sudoku-pro e",
|
|
17
18
|
"medium": "node sudoku-pro m",
|
|
18
|
-
"hard": "node sudoku-pro h"
|
|
19
|
+
"hard": "node sudoku-pro h",
|
|
20
|
+
"very": "node sudoku-pro v"
|
|
19
21
|
},
|
|
20
22
|
"files": [
|
|
21
23
|
"sudoku-pro.js"
|
|
@@ -33,6 +35,7 @@
|
|
|
33
35
|
"Easy Sudoku",
|
|
34
36
|
"Medium Sudoku",
|
|
35
37
|
"Hard Sudoku",
|
|
38
|
+
"Very hard Sudoku",
|
|
36
39
|
"Brain Teaser",
|
|
37
40
|
"Puzzle",
|
|
38
41
|
"Puzzle Game",
|
package/sudoku-pro.js
CHANGED
|
@@ -32,18 +32,23 @@ function generateSudoku(difficulty) {
|
|
|
32
32
|
|
|
33
33
|
// Determine the number of cells to remove based on difficulty level
|
|
34
34
|
let numToRemove;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
switch (difficulty) {
|
|
36
|
+
case "e":
|
|
37
|
+
numToRemove = ensureNumToRemoveInRange(20, 20); // Easy difficulty
|
|
38
|
+
break;
|
|
39
|
+
case "m":
|
|
40
|
+
numToRemove = ensureNumToRemoveInRange(25, 50); // Medium difficulty
|
|
41
|
+
break;
|
|
42
|
+
case "h":
|
|
43
|
+
numToRemove = ensureNumToRemoveInRange(30, 60); // Hard difficulty
|
|
44
|
+
break;
|
|
45
|
+
case "v":
|
|
46
|
+
numToRemove = ensureNumToRemoveInRange(35, 75); // Very hard difficulty
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(
|
|
50
|
+
'Invalid difficulty level. Please use "e" for easy, "m" for medium, "h" for hard, or "v" for very hard.'
|
|
51
|
+
);
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
// Create a copy of the solved Sudoku to remove cells from
|
|
@@ -63,6 +68,14 @@ function generateSudoku(difficulty) {
|
|
|
63
68
|
return { sudoku: sudokuCopy, solvedSudoku };
|
|
64
69
|
}
|
|
65
70
|
|
|
71
|
+
function ensureNumToRemoveInRange(lowerBound, upperBound) {
|
|
72
|
+
let numToRemove;
|
|
73
|
+
do {
|
|
74
|
+
numToRemove = Math.floor(Math.random() * lowerBound) + upperBound;
|
|
75
|
+
} while (numToRemove > 81); // Ensure numToRemove is within the range 0-81
|
|
76
|
+
return numToRemove;
|
|
77
|
+
}
|
|
78
|
+
|
|
66
79
|
function solveSudoku(sudoku) {
|
|
67
80
|
const emptyCell = findEmptyCell(sudoku);
|
|
68
81
|
if (!emptyCell) {
|