Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 1.45 KB

pseudocode.md

File metadata and controls

24 lines (17 loc) · 1.45 KB

Naked Twins

The naked twins strategy says that if you have two or more unallocated boxes in a unit and there are only two digits that can go in those two boxes, then those two digits can be eliminated from the possible assignments of all other boxes in the same unit.

This pseudocode is accurate, but it isn't very efficient. You should discuss the other strategies with your peers to look for more efficient implementations.

Note: It is best to treat the input to this function as immutable. Mutating the state during execution can cause unexpected results during testing because mutating the input can erase pairs of naked twins before they're discovered.


function NakedTwins(values) returns a dict mapping from Sudoku box names to a list of feasible values
inputs:
  values, a dict mapping from Sudoku box names to a list of feasible values

out <- copy(values) /* make a deep copy */
for each boxA in values do
  for each boxB of PEERS(boxA) do
   if both values[boxA] and values[boxB] exactly match and have only two feasible digits do
    for each peer of INTERSECTION(PEERS(boxA), PEERS(boxB)) do
     for each digit of values[boxA] do
      remove digit d from out[peer]
return out