### Sudoku Solver (Brutish way)

Hi guys! I wrote a program in C++ to solve Sodoku. I just cant figure whats wrong with it.......

I've written //comments everywhere for understanding the code easier.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 #include using namespace std; int main() { //Initiallizing the variables int board[9][9][10]; int x, y, n; //Initiallizing the board for (int i=0;i<9;i++) { for (int j=0;j<9;j++) { for (int k=0;k<10;k++) { board[i][j][k] = k; } } } //In the array k[x][y][z], z is the possibles values of the square. We take k[x][y][0] as the entered //number. If k[x][y][0] == 0, then its a blank. //Getting the numbers cout<<"**** Enter 0 for a blank in the Sudoku "<>board[x][y][0]; } while (board[x][y][0]>10 ); } } //Seting all extra variables to zero and defining a few new ones that will be used later. x = 0; y = 0; n = 0; // k = 0; int i = 0; int j = 0; int size = 0; int o; int count1, count2; int temp; int z; int q,k,l; //ALGORITHIM BEGINS ------------------------------------------------------------------------------------------------------------------------------ //Now to loop onto infinity until all the boxes get filled. do { // ---- part.1 - TERMINATING THE VALUES IN EACH ROW, COLOUMN AND BOX ---- //Initializing hte conters count1 = 0; count2 = 0; //Terminiating possibilities in each row. for (i=0;i<9;i++) { for (j=0;j<9;j++) { for (n=1;n<9;n++) { //-- if (board[i][j][0] == n) { //-- for (k=0;k<9;k++) { for (l=0;l<10;l++) { if (board[i][k][l] == n) board[i][k][l] = 0; } } //-- } //-- } } } //Terminiating possibilities in each column. for (j=0;j<9;j++) { for (i=0;i<9;i++) { for (n=1;n<9;n++) { //-- if (board[i][j][0] == n) { //-- for (q=0;q<9;q++) { for (l=0;l<10;l++) { if (board[q][j][l] == n) board[q][j][l] = 0; } //-- } } //-- } } } //Terminiating possibilities in each box. /* The box pattern is shown below : 1 | 2 | 3 4 | 5 | 6 7 | 8 | 9 */ //Box no.1 for (i=0;i<3;i++) { for (j=0;j<3;j++) { for (n=1;n<10;n++) { //-- if (board[i][j][0] == n) { //-- for (q=0;q<3;q++) { for (k=0;k<3;k++) { for (l=0;l<10;l++) { if (board[q][k][l] == n) board[q][k][l] = 0; } } } //-- } //-- } } } //Box no.2 for (i=0;i<3;i++) { for (j=3;j<6;j++) { for (n=1;n<10;n++) { //-- if (board[i][j][0] == n) { for (q=0;q<3;q++) { for (k=3;k<6;k++) { for (l=0;l<10;l++) { if (board[q][k][l] == n) board[q][k][l] = 0; } } } } //-- } } } //Box no.3 for (i=0;i<3;i++) { for (j=6;j<9;j++) { for (n=1;n<10;n++) { //-- if (board[i][j][0] == n) { for (q=0;q<3;q++) { for (k=6;k<9;k++) { for (l=0;l<10;l++) { if (board[q][k][l] == n) board[q][k][l] = 0; } } } } //-- } } } //Box no.4 for (i=3;i<6;i++) { for (j=0;j<3;j++) { for (n=1;n<10;n++) { //-- if (board[i][j][0] == n) { for (q=3;q<6;q++) { for (k=0;k<3;k++) { for (l=0;l<10;l++) { if (board[q][k][l] == n) board[q][k][l] = 0; } } } } //-- } } } //Box no.5 for (i=3;i<6;i++) { for (j=3;j<6;j++) { for (n=1;n<10;n++) { //-- if (board[i][j][0] == n) { for (q=3;q<6;q++) { for (k=3;k<6;k++) { for (l=0;l<10;l++) { if (board[q][k][l] == n) board[q][k][l] = 0; } } } } //-- } } } //Box no.6 for (i=3;i<6;i++) { for (j=6;j<9;j++) { for (n=1;n<10;n++) { //-- if (board[i][j][0] == n) { for (q=3;q<6;q++) { for (k=6;k<9;k++) { for (l=0;l<10;l++) { if (board[q][k][l] == n) board[q][k][l] = 0; } } } } //-- } } } //Box no.7 for (i=6;i<9;i++) { for (j=0;j<3;j++) { for (n=1;n<10;n++) { //-- if (board[i][j][0] == n) { for (q=6;q<9;q++) { for (k=0;k<3;k++) { for (l=0;l<10;l++) { if (board[q][k][l] == n) board[q][k][l] = 0; } } } } //-- } } } //Box no.8 for (i=6;i<9;i++) { for (j=3;j<6;j++) { for (n=1;n<10;n++) { //-- if (board[i][j][0] == n) { for (q=6;q<9;q++) { for (k=3;k<6;k++) { for (l=0;l<10;l++) { if (board[q][k][l] == n) board[q][k][l] = 0; } } } } //-- } } } //Box no.9 for (i=6;i<9;i++) { for (j=6;j<10;j++) { for (n=1;n<9;n++) { //-- if (board[i][j][0] == n) { for (q=6;q<9;q++) { for (k=6;k<9;k++) { for (l=0;l<10;l++) { if (board[q][k][l] == n) board[q][k][l] = 0; } } } } //-- } } } // ---- part.2 - ASSIGNING FINAL VALUES TO THE BOX AND DISPLAYING THE BOARD ---- for ( x = 0; x < 9; x++ ) { for ( y = 0; y < 9; y++ ) { for (z = 0; z < 10; z++) { if (board[x][y][z] == 0) { count1++; } else {temp = board[x][y][z];} if(count1==8) { board[x][y][0] = temp; } //CHANGE } } } system ("CLS"); for ( x = 0; x < 9; x++ ) { for ( y = 0; y < 9; y++ ) { if (board[x][y][0] == 0) {count2++;} } } //Displaying the board cout<