Last active
May 19, 2017 15:41
-
-
Save chashmeetsingh/a67183b106a3894f79ea061cd053178a 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 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