@@ -9,37 +9,42 @@ class Sudoku {
99 List <List <int >> matSolved = new List .generate (
1010 9 , (i) => [null , null , null , null , null , null , null , null , null ]);
1111
12- Sudoku ([String difficulty= 'easy' ]) {
13- switch (difficulty){
14- case 'test' : {
15- this .K = 2 ;
16- }
17- break ;
18- case 'beginner' : {
19- this .K = 18 ;
20- }
21- break ;
22- case 'easy' : {
23- this .K = 27 ;
24- }
25- break ;
26- case 'medium' : {
27- this .K = 36 ;
28- }
29- break ;
30- case 'hard' : {
31- this .K = 54 ;
32- }
33- break ;
12+ Sudoku ([String difficulty = 'easy' ]) {
13+ switch (difficulty) {
14+ case 'test' :
15+ {
16+ this .K = 2 ;
17+ }
18+ break ;
19+ case 'beginner' :
20+ {
21+ this .K = 18 ;
22+ }
23+ break ;
24+ case 'easy' :
25+ {
26+ this .K = 27 ;
27+ }
28+ break ;
29+ case 'medium' :
30+ {
31+ this .K = 36 ;
32+ }
33+ break ;
34+ case 'hard' :
35+ {
36+ this .K = 54 ;
37+ }
38+ break ;
3439 }
3540 fillValues ();
3641 }
3742
3843 static List <List <int >> copyGrid (List <List <int >> grid) {
3944 List <List <int >> copiedGrid = new List .generate (
4045 9 , (i) => [null , null , null , null , null , null , null , null , null ]);
41- for (int i= 0 ;i < 9 ; i++ ) {
42- for (int j= 0 ;j < 9 ; j++ ) {
46+ for (int i = 0 ; i < 9 ; i++ ) {
47+ for (int j = 0 ; j < 9 ; j++ ) {
4348 copiedGrid[i][j] = grid[i][j];
4449 }
4550 }
@@ -90,8 +95,8 @@ class Sudoku {
9095
9196 int randomGeneratorK () {
9297 List <int > numberList = new List <int >(81 );
93- for (int i= 0 ;i < N * N ; i++ ){
94- numberList[i]= i;
98+ for (int i = 0 ; i < N * N ; i++ ) {
99+ numberList[i] = i;
95100 }
96101 numberList.shuffle ();
97102 return numberList[0 ];
@@ -160,18 +165,18 @@ class Sudoku {
160165 }
161166
162167 void removeKDigits () {
163- while (K > 0 ) {
164- int row = randomGenerator ()- 1 ;
165- int col = randomGenerator ()- 1 ;
166- while (mat[row][col]== 0 ) {
167- row = randomGenerator ()- 1 ;
168- col = randomGenerator ()- 1 ;
168+ while (K > 0 ) {
169+ int row = randomGenerator () - 1 ;
170+ int col = randomGenerator () - 1 ;
171+ while (mat[row][col] == 0 ) {
172+ row = randomGenerator () - 1 ;
173+ col = randomGenerator () - 1 ;
169174 }
170175 int backup = mat[row][col];
171- mat[row][col]= 0 ;
176+ mat[row][col] = 0 ;
172177 List <List <int >> copy = copyGrid (mat);
173178 Solve test = Solve (copy);
174- if (test.noOfSolutions!= 1 ) {
179+ if (test.noOfSolutions != 1 ) {
175180 mat[row][col] = backup;
176181 }
177182 K -- ;
0 commit comments