This code solves a Sudoku puzzle with no starting values perfectly..
But if i then in some values to start with it moves them around to suit itself which cannot happen.
Can anybody see the problem in the code? because it is frying my brain!
public boolean solve(int row, int col) { if (row == 9) { row = 0; col++; } if (col == 9 ) { return true; //Base case - puzzle solved. } Object checkHelp = board[row][col]; String s = checkHelp.toString().trim(); if(s.equals('1') ||s.equals('2') ||s.equals('3') ||s.equals('4') ||s.equals('5') || s.equals('6') ||s.equals('7') ||s.equals('8') ||s.equals('9') ) // skip filled cells { solve(row+1,col); //recursive call } for(int val = 1; val <10;val++) { if (valid(row,col,val,board)) //checks if value is legal { Object input = val; String z = input.toString().trim(); board[row][col] = z.charAt(0);; fireTableCellUpdated(row, col); if (solve(row+1,col)) //call solve starting at next cell { return true; } } } board[row][col] = '0'; // reset on backtrack return false; }