-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSudokuSolver.java
More file actions
28 lines (22 loc) · 872 Bytes
/
Copy pathSudokuSolver.java
File metadata and controls
28 lines (22 loc) · 872 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
import java.util.Scanner;
public class SudokuSolver {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[][] board = new int[9][9];
System.out.println("Enter the Sudoku grid row by row (use 0 for empty spaces):");
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
board[i][j] = scanner.nextInt();
}
}
scanner.close();
SudokuState initialState = new SudokuState(board);
SudokuState solvedState = SudokuState.backtrackingSearch(initialState);
if (solvedState != null) {
System.out.println("Solved Sudoku:");
System.out.println(solvedState);
} else {
System.out.println("No solution found for this Sudoku.");
}
}
}