Skip to content

Instantly share code, notes, and snippets.

@zahash
Last active January 10, 2019 12:36
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 zahash/eb9401d1a2aece8dbf5383194e1cc50c to your computer and use it in GitHub Desktop.
Save zahash/eb9401d1a2aece8dbf5383194e1cc50c to your computer and use it in GitHub Desktop.
def run_episode(grid_dict):
stuck = False
while not stuck:
# Check how many boxes have a fixed value
solved_values_before = len([box for box in grid_dict.keys() if len(grid_dict[box]) == 1])
# Use the Eliminate Strategy
grid_dict = eliminate(grid_dict)
# Use the Only Choice Strategy
grid_dict = only_choice(grid_dict)
# Check how many boxes have a fixed value now
solved_values_after = len([box for box in grid_dict.keys() if len(grid_dict[box]) == 1])
# If there is no change, stop the loop.
stuck = solved_values_before == solved_values_after
# if the current sudoku configuration is un-solvable then return False
if len([box for box in grid_dict.keys() if len(grid_dict[box]) == 0]):
return False
return grid_dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment