March 7th, 2009, 08:43 PM
Help with Brute-Force Sudoku Solver?
This solver seems to work for some Sudokus, but it does nothing for others. Can anyone see something wrong? Thanks.
Oh, and my Sudoku is made of a two-dimensional array.
public void solve()
boolean findEmpty = false;
int i = 0;
int j = 0;
for ( i = 0 ; i < 6 && !findEmpty ; i++ )
for ( j = 0 ; j < 9 && !findEmpty ; j++ )
if ( sudoku.getGrid()[i][j] == 0 )
findEmpty = true;
j--; // return i and j to values of row and col where sudoku is empty
for ( int k = 1 ; k <= 9 ; k++ )
if ( isLegal( i , j , k ) )
sudoku.getGrid()[i][j] = k;
if ( isComplete() )
sudoku.getGrid()[i][j] = 0;
Last edited by Sinfonia; March 7th, 2009 at 08:50 PM.
March 9th, 2009, 10:52 AM
Re: Help with Brute-Force Sudoku Solver?
Please use the code tags, it is hard to read code without them.
Personally I don't know how your solver is working for "any" Sudoku. You are checking a 6 by 9 area and a Sudoku puzzle is 9 by 9... I would run it in debug mode and step through the code if I were you.
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!