| Robert Larsen
| Joined: 21 Oct 2005 | Posts: 1 | : | | Items |
|
Posted: Fri Oct 21, 2005 3:52 pm Post subject: Problem creating larger sudokus |
|
|
Hi all
I am building a Sudoku generator (isn't everybody ?) and is having some problems.
It is supposed to be able to build Sudokus with 2x2, 3x3 and 4x4 boxes.
Mkay...this is what I do:
I have a number of 'solver' classes which implement different solving techniques.
When creating a Sudoku I start off with an empty board and then enter the following loop (pseudo code):
Code: |
myBoard.clear();
myCopy.clear();
while(myBoard.isNotCompletelySolved()) {
myBoard.clear();
myCopy.clear();
while(myBoard.allNumbersRepresentedInRowsColsAndBoxes() && myBoard.isNotCompletelySolved()) {
myBoard.setOneNumberLegally();
myBoard.setLastSetNumberInBoard(myCopy);
myBoard.solveAsMuchAsPossible();
}
}
myCopy.removeRandomNumbersLeavingOnlyOneSolution();
|
This seems to work for 2x2 and 3x3 but the 4x4 size always end up failing to have a solution so the outer loop is endless.
Is there a better generic way to generate different sized Sudokus ? |
|