Guest User

Untitled

a guest
May 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. from utils import *
  2. from collections import Counter
  3.  
  4. def only_choice(values):
  5. """Finalize all values that are the only choice for a unit.
  6.  
  7. Go through all the units, and whenever there is a unit with a value
  8. that only fits in one box, assign the value to this box.
  9.  
  10. Input: Sudoku in dictionary form.
  11. Output: Resulting Sudoku in dictionary form after filling in only choices.
  12. """
  13. # TODO: Implement only choice strategy here
  14. # display(values)
  15. for unit in unitlist:
  16. c = Counter()
  17. for box in unit:
  18. c.update(values[box])
  19. for box in unit:
  20. for value in values[box]:
  21. if c[value] == 1 and len(values[box]) > 1:
  22. values[box] = value
  23. return values
Add Comment
Please, Sign In to add comment