-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSudokusolver.java
More file actions
34 lines (32 loc) · 863 Bytes
/
Sudokusolver.java
File metadata and controls
34 lines (32 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class Sudokusolver {
public static boolean sudokoSolver(int arr[],int row, int j){
//base case
if(row== 9 && j == 9){
return true;
}else if(row== 9){
return false;
}
//recursion
int nextRow = i, nextCol = j+1;
if(j+1 == 9){
nextRow = i+1;
nextCol = 0;
}
if(arr[i][j] != 0){
return sudokoSolver(arr, nextRow, nextCol)
}
for(int digit= 1;digit <=9 ;digit++){
if(isSafe(arr, i, j , digit)){
arr[i][j] = digit;
if(sudokoSolver(arr, nextRow, nextCol)){
return true;
}
arr[i][j] = 0;
}
}
return false;
}
public static void main(String args[]){
int sudoku[] =
}
}