SudokuFunctions.py
def naked_twins(values):
    """Eliminate values using the naked twins strategy.

    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.

    Parameters
    ----------
    values(dict)
        a dictionary of the form {'box_name': '123456789', ...}

    Returns
    -------
    dict
        The values dictionary with the naked twins eliminated from peers
    """
    
    ## We loop over each unit in the unitlist
    for unit in unitlist:
        unit_pairs = [u for u in unit if len(values[u])==2]
        ## We get the boxes that have exactly 2 values only, and THEN check if there is more than one box
        if len(unit_pairs) > 1:
            ## We make pair of boxes that have exactly the 2 same values (and ommit making pairs of the same box two times)
            twin_boxes = [(u,i) for u in unit_pairs for i in unit_pairs[unit_pairs.index(u):] if values[u] == values[i] and unit_pairs.index(u)!=unit_pairs.index(i)]
            ## We loop over the pairs of boxes founded (the pairs of boxes with 2 identical values)
            for pair in twin_boxes:
                ## We define the other boxes from the unit (different from the pair with 2 identical values)
                other_boxes = [u for u in unit if u != pair[0] and u != pair[1]]
                ## We erase those values from the other boxes
                for o_box in other_boxes:
                    values[o_box] = values[o_box].replace(values[pair[0]][0],"")
                    values[o_box] = values[o_box].replace(values[pair[0]][1],"")
    return values
    
    raise NotImplementedError
Eliminate values using the naked twins strategy.

    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.

    Parameters
    ----------
    values(dict)
        a dictionary of the form {'box_name': '123456789', ...}

    Returns
    -------
    dict
        The values dictionary with the naked twins eliminated from peers
    
Eliminate values using the naked twins strategy.
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.

Parameters



Returns

dict
The values dictionary with the naked twins eliminated from peers
Eliminate values using the naked twins strategy . 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 . Parameters Returns dict The values dictionary with the naked twins eliminated from peers
def naked_twins(values):
    for unit in unitlist:
        unit_pairs = [u for u in unit if len(values[u])==2]
        if len(unit_pairs) > 1:
            twin_boxes = [(u,i) for u in unit_pairs for i in unit_pairs[unit_pairs.index(u):] if values[u] == values[i] and unit_pairs.index(u)!=unit_pairs.index(i)]
            for pair in twin_boxes:
                other_boxes = [u for u in unit if u != pair[0] and u != pair[1]]
                for o_box in other_boxes:
                    values[o_box] = values[o_box].replace(values[pair[0]][0],"")
                    values[o_box] = values[o_box].replace(values[pair[0]][1],"")
    return values
    raise NotImplementedError
def naked_twins ( values ) : for unit in unitlist : unit_pairs = [ u for u in unit if len ( values [ u ] ) == 2 ] if len ( unit_pairs ) > 1 : twin_boxes = [ ( u , i ) for u in unit_pairs for i in unit_pairs [ unit_pairs . index ( u ) : ] if values [ u ] == values [ i ] and unit_pairs . index ( u ) != unit_pairs . index ( i ) ] for pair in twin_boxes : other_boxes = [ u for u in unit if u != pair [ 0 ] and u != pair [ 1 ] ] for o_box in other_boxes : values [ o_box ] = values [ o_box ] . replace ( values [ pair [ 0 ] ] [ 0 ] , "" ) values [ o_box ] = values [ o_box ] . replace ( values [ pair [ 0 ] ] [ 1 ] , "" ) return values raise NotImplementedError
Eliminate values using the naked twins strategy.
Eliminate values using the naked twins strategy .
"""Eliminate values using the naked twins strategy.

    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.

    Parameters
    ----------
    values(dict)
        a dictionary of the form {'box_name': '123456789', ...}

    Returns
    -------
    dict
        The values dictionary with the naked twins eliminated from peers
    """ ## We loop over each unit in the unitlist ## We get the boxes that have exactly 2 values only, and THEN check if there is more than one box ## We make pair of boxes that have exactly the 2 same values (and ommit making pairs of the same box two times) ## We loop over the pairs of boxes founded (the pairs of boxes with 2 identical values) ## We define the other boxes from the unit (different from the pair with 2 identical values) ## We erase those values from the other boxes
values