from utils import * def reduce_puzzle(values): stalled = False count = 1 while not stalled: # Check how many boxes have a determined value solved_values_before = len([box for box in values.keys() if len(values[box]) == 1]) # Your code here: Use the Eliminate Strategy values = eliminate(values) # Your code here: Use the Only Choice Strategy values = only_choice(values) # Check how many boxes have a determined value, to compare solved_values_after = len([box for box in values.keys() if len(values[box]) == 1]) # If no new values were added, stop the loop. stalled = solved_values_before == solved_values_after # Stop looping if the puzzle is solved. if solved_values_after == len(values): #print('Solution found after ' + str(count) + ' iterations.') stalled = True # Sanity check, return False if there is a box with zero available values: if len([box for box in values.keys() if len(values[box]) == 0]): return False count = count + 1 return values