Skip to content

Instantly share code, notes, and snippets.

@rharriso
Created June 26, 2017 18:46
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/257fc72c6b0203d482a7e01eaa991fcb to your computer and use it in GitHub Desktop.
Save rharriso/257fc72c6b0203d482a7e01eaa991fcb to your computer and use it in GitHub Desktop.
available_options = (1..9)
def fillCells:
doFillCells(0)
def doFillCells (index):
cell = board.cells[index]
neighbor_values = cell.neighbors.map((neighbor) => neighbor.values)
remaining_options = available_options \ neighbor_values
for option in remaining_options:
cell.value = options
if index == board.cells.count() - 1:
return true
if doFillCells(index + 1):
return true
# backtrack
cell.value = 0
return false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment