Last active
May 1, 2017 00:39
-
-
Save rharriso/c56566fc50f73639a7d447e7c16b5d44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using cellQueue = std::deque<SudokuCell>; | |
class SudokuBoard { | |
/* | |
* fill the board with valid solution | |
*/ | |
void fillCells() { | |
auto remaininCells = cellQueue{cells}; | |
if(!doFillCells(remaininCells)) { | |
cout << "Unable to fill board" << endl; | |
} | |
} | |
bool doFillCells(cellQueue &remainingCells) { | |
// get first cell and tail | |
auto cell = remainingCells.front(); | |
remainingCells.pop_front(); | |
// collected from all the neighbor values | |
set<int> neighborValues = {}; | |
// produced by set difference VALID_VALUES \ neighbord values | |
vector<int> options; | |
for(auto option : options) { | |
cell->value = option; | |
// base case (no remaining cells) | |
if (remainingCells.empty()) { | |
return true; | |
} | |
// recursive step | |
if (doFillCells(remainingCells)){ | |
return true; | |
}; | |
} | |
// base case (push cell back to set, and backtrack) | |
cell->value = 0; | |
remainingCells.push_front(cell); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment