Skip to content

Instantly share code, notes, and snippets.

@chashmeetsingh
Last active May 19, 2017 15:41
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 chashmeetsingh/a67183b106a3894f79ea061cd053178a to your computer and use it in GitHub Desktop.
Save chashmeetsingh/a67183b106a3894f79ea061cd053178a to your computer and use it in GitHub Desktop.
def naked_twins(values):
"""Eliminate values using the naked twins strategy.
Args:
values(dict): a dictionary of the form {'box_name': '123456789', ...}
Returns:
the values dictionary with the naked twins eliminated from peers.
"""
twins = []
# Find all instances of naked twins
for box in values.keys():
for unit_list in units[box]:
for unit in unit_list:
if values[unit] == values[box]:
twins.append([box, unit_list])
# Eliminate the naked twins as possibilities for their peers
for box, unit_list in twins:
for unit in unit_list:
for value in values[box]:
if value in values[unit] and len(values[unit]) > 1 and values[unit] != values[box]:
values[unit] = values[unit].replace(value,'')
return values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment