SHARE
TWEET

Untitled

a guest Nov 19th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int play_sudoku_bruteforce(int matrix[][N],int lines,int columns) {
  2.     if ((lines == N - 1 && columns == N - 1)) {
  3.         printf("\t SUDOKU COMPLETADO ! \n");
  4.         print_matrix(matrix, lines);
  5.         return 0;
  6.     }
  7.     if (checkConsistency(matrix, lines, columns)) { // ESTÁ DENTRO DA MATRIZ E ESTA A 0
  8.         for (int i = 1; i <= N; i++) {
  9.             if (!checkSecDiagonal(matrix, i) && !checkSquare(matrix, lines, columns, i) &&
  10.                 !checkLine(matrix, lines, i) && !checkColumn(matrix, columns, i) &&
  11.                 !checkMainDiagonal(matrix, i)) // VERIFICAR SE ESTA NA DIAGONAL PRINCIPAL E SECUNDARIA
  12.             {
  13.                 matrix[lines][columns] = i;
  14.                 return play_sudoku_bruteforce(matrix, lines, columns + 1);
  15.             } else if (!checkLine(matrix, lines, i) && !checkMainDiagonal(matrix, i) &&
  16.                        !checkColumn(matrix, columns, i) && !checkSquare(matrix, lines, columns, i) &&
  17.                        (lines == columns)) { // VERIFICA SE TEM NA DIAGONAL PRINCIPAL
  18.                 matrix[lines][columns] = i;
  19.                 if (columns == N - 1) {
  20.                     return play_sudoku_bruteforce(matrix, N - 1, N - 1);
  21.                 } else return play_sudoku_bruteforce(matrix, lines, columns + 1);
  22.             } else if (!checkLine(matrix, lines, i) && !checkSecDiagonal(matrix, i) &&
  23.                        !checkColumn(matrix, columns, i) && !checkSquare(matrix, lines, columns, i) &&
  24.                        (lines + columns == N - 1)) { //VERIFICA SE TEM NA DIAGONAL SECUNDARIA
  25.                 matrix[lines][columns] = i;
  26.                 if (columns == N - 1) {
  27.                     return play_sudoku_bruteforce(matrix, lines + 1, 0);
  28.                 } else return play_sudoku_bruteforce(matrix, lines, columns + 1);
  29.             } else if (!checkLine(matrix, lines, i) && !checkColumn(matrix, columns, i) &&
  30.                        !checkSquare(matrix, lines, columns, i)) {
  31.                 matrix[lines][columns] = i;
  32.                 if (columns == N - 1) {
  33.                     return play_sudoku_bruteforce(matrix, lines + 1, 0);
  34.                 } else return play_sudoku_bruteforce(matrix, lines, columns + 1);
  35.             }
  36.         }
  37.  
  38.     }
  39.     return 0;
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top