Need Multiple Sudoku Solutions
- by user1567909
I'm trying to output multiple sudoku solutions in my program. For example, when You enter this as input:
8..6..9.5.............2.31...7318.6.24.....73...........279.1..5...8..36..3......
.'s denote blank spaces. Numbers represent already-filled spaces. The output should be a sudoku solution like so:
814637925325149687796825314957318462241956873638274591462793158579481236183562749
However, I want to output multiple solutions. This would be all the solutions that should be printed:
814637925325149687796825314957318462241956873638274591462793158579481236183562749
814637925325941687796825314957318462241569873638472591462793158579184236183256749
834671925125839647796425318957318462241956873368247591682793154579184236413562789
834671925125839647796524318957318462241956873368247591682793154519482736473165289
834671925125839647796524318957318462241965873368247591682793154519482736473156289
But my program only prints out one solution. Below is my recursive solution to solving a sudoku solution
bool sodoku::testTheNumber(sodoku *arr[9][9], int row, int column)
{
if(column == 9)
{
column = 0;
row++;
if(row == 9)
return true;
}
if(arr[row][column]->number != 0)
{
return testTheNumber(arr, row, column+1);
}
for(int k = 1; k < 10; k++)
{
if(k == 10)
{
arr[row][column]->number = 0;
return false;
}
if(rowIsValid(arr, k, row) && columnIsValid(arr, k, column) && boxIsValid(arr, k, row, column))
{
arr[row][column]->number = k;
if(testTheNumber(arr, row, column+1)==true)
{
return true;
}
arr[row][column]->number = 0;
}
}
return false;
}
Could anyone help me come up with a way to print out multiple solutions? Thanks.