Last active
January 10, 2019 12:36
-
-
Save zahash/eb9401d1a2aece8dbf5383194e1cc50c to your computer and use it in GitHub Desktop.
This file contains 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
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