Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. static void printSolution(SudokuBoard board) {
  2.  
  3. SudokuBoard resultBoard = findSolution(board);
  4.  
  5. if(resultBoard != null) {
  6. resultBoard.print();
  7. }
  8. }
  9.  
  10. static SudokuBoard findSolution(SudokuBoard board) {
  11.  
  12. if (board.isSolved()) {
  13. return board;
  14.  
  15. } else {
  16.  
  17. int freiesNaechstesFeld = getNextFreeIndex(board);
  18.  
  19. if (freiesNaechstesFeld != -1) {
  20.  
  21. int[] kandidaten = board.getCandidates(freiesNaechstesFeld);
  22.  
  23. for (int i = 0; i < kandidaten.length; i++) {
  24.  
  25. SudokuBoard newBoard = board.set(freiesNaechstesFeld,
  26. kandidaten[i]);
  27.  
  28. return findSolution(newBoard);
  29. }
  30. }
  31.  
  32. return null;
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement