Here's my solution.
public static boolean isValid(int i, int j, int v) {
for (int k = 0; k < LENGTH; k++)
if ( (table[ i ][ k ] == v) || (table[ k ] [ j ] == v) )
return false;
i = i % COUNT_SUBTABLES == 0 ? i
: (i - 1) % COUNT_SUBTABLES == 0 ? i - 1
: i - 2;
j = j % COUNT_SUBTABLES == 0 ? j
: (j - 1) % COUNT_SUBTABLES == 0 ? j - 1
: j - 2;
final int limI = i + LENGTH_SUBTABLES;
final int limJ = j + LENGTH_SUBTABLES;
for (int rI = i; rI < limI; rI++) {
for (int rJ = j; rJ < limJ; rJ++) {
if (table[ rI ][ rJ ] == v)
return false;
}
}
return true;
}
public static void soduko(int i, int j) {
if (i == 9) {
print();
System.out.println("-----------------------");
return;
}
for(int v = 1; v <= 9; v++) {
if (isValid(i,j,v)) {
table[ i ] [ j ] = v;
soduko(j < LONGITUD - 1 ? i : i + 1, j < LONGITUD - 1 ? j + 1 : 0);
table[ i ][ j ] = 0;
}
}
}
Any one have any ideas for a very efficient suduko puzzle solver? I am
currently using one I just thought of, but it is kind of slow.
Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---
- [algogeeks] Suduko Solving Algorithm [EMAIL PROTECTED]
- [algogeeks] Re: Suduko Solving Algorithm Roberto Abreu
- [algogeeks] Re: Suduko Solving Algorithm crooks_dwayne