Skip to content

Instantly share code, notes, and snippets.

@jezinka
Created October 17, 2018 16:51
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 jezinka/a7fc3d53889b73d98bf45a33b84f4928 to your computer and use it in GitHub Desktop.
Save jezinka/a7fc3d53889b73d98bf45a33b84f4928 to your computer and use it in GitHub Desktop.
void fillCandidates() {
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[i].length; j++) {
Cell cell = board[i][j]
if (cell.value == 0) {
cell.candidates = (1..9)
removeKnown(i, j)
assert cell.candidates.size() > 0
} else {
cell.candidates = []
}
}
}
}
void removeKnown(int rowNum, int colNum) {
Cell cell = board[rowNum][colNum]
cell.candidates -= getValuesForColumn(colNum)
cell.candidates -= getValuesForRecord(rowNum)
cell.candidates -= getValuesForSquare(rowNum, colNum)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment