Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void printSolution(SudokuBoard board) {
- SudokuBoard resultBoard = findSolution(board);
- if(resultBoard != null) {
- resultBoard.print();
- }
- }
- static SudokuBoard findSolution(SudokuBoard board) {
- if (board.isSolved()) {
- return board;
- } else {
- int freiesNaechstesFeld = getNextFreeIndex(board);
- if (freiesNaechstesFeld != -1) {
- int[] kandidaten = board.getCandidates(freiesNaechstesFeld);
- for (int i = 0; i < kandidaten.length; i++) {
- SudokuBoard newBoard = board.set(freiesNaechstesFeld,
- kandidaten[i]);
- return findSolution(newBoard);
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement