Skip to content

Instantly share code, notes, and snippets.

@rharriso
Last active April 30, 2017 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rharriso/76ffe4556bb1c82507f3a4cf4ffff039 to your computer and use it in GitHub Desktop.
Save rharriso/76ffe4556bb1c82507f3a4cf4ffff039 to your computer and use it in GitHub Desktop.
bool fillCells() {
for(auto cell : this->cells()) {
// get first cell and tail
auto cell = remainingCells.front();
remainingCells.pop_front();
set<int> neighborValues = {};
for(auto &neighbor : cell->neighbors) {
auto value = this->at(neighbor)->value;
neighborValues.insert(value);
}
vector<int> options;
set_difference(VALID_VALUES.begin(), VALID_VALUES.end(),
neighborValues.begin(), neighborValues.end(),
inserter(options, options.begin())
);
random_shuffle(options.begin(), options.end());
cell->value = options[0];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment