62
edits
Changes
→Assignment 1
c) Else, remove digit and try another
If all digits have been tried and nothing worked, return false
===Sudoku Backtrack Function===
/* Takes a partially filled-in grid and attempts to assign values to
all unassigned locations in such a way to meet the requirements
for Sudoku solution (non-duplication across rows, columns, and boxes) */
bool SolveSudoku(int grid[N])
{
int row, col;
// If there is no unassigned location, we are done
if (!FindUnassignedLocation(grid, row, col))
return true; // success!
// consider digits 1 to 16
for (int num = 1; num <= n; num++)
{
// if looks promising
if (isSafe(grid, row, col, num))
{
// make tentative assignment
grid[(row)+(col*n)] = num;
// return, if success, yay!
if (SolveSudoku(grid))
return true;
// failure, unmake & try again
grid[(row)+(col*n)] = UNASSIGNED;
}
}
return false; // this triggers backtracking
}
===Source===
http://www.geeksforgeeks.org/backtracking-set-7-suduku/
== Assignment 2 ==