def naked_sets_sudoku(medium_sudoku):
    from sudoku_solver_hard import setup, scan_sudoku, fill_fit, single_candidate
    m = medium_sudoku
    candidates, dicts, square_coords = setup(m)
    rm, cm, sm = dicts
    m = scan_sudoku(m, dicts, square_coords, candidates)
    candidates, dicts, square_coords = setup(m)
    single_candidates = single_candidate(candidates, square_coords, dicts)
    m = fill_fit(m, dicts, square_coords, single_candidates=single_candidates)
    return m
def test_fill_fit_candidates(medium_sudoku):
    """Test that given candidates with immediate fits, the Sudoku is updated correctly
    and the fill is removed from Sudoku dicts."""
    from sudoku_solver_hard import setup, fill_fit
    m = medium_sudoku
    c, dicts, square_coords = setup(m)
    m = fill_fit(m, dicts, square_coords, candidates=c)
    c, dicts, square_coords = setup(m)
    rm, cm, sm = dicts
    assert m[4][4] == 3
    assert m[2][4] == 6
    assert m[6][4] == 5
    assert 3 not in rm[4]
Exemplo n.º 3
0
def naked_sets_sudoku(medium_sudoku, immediate_fills_dicts,
                      immediate_fills_candidates):
    from sudoku_solver_hard import scan_sudoku, fill_fit, single_candidate
    m = medium_sudoku
    dicts, square_coords = immediate_fills_dicts
    rm, cm, sm = dicts
    m, candidates = scan_sudoku(m, dicts, square_coords,
                                immediate_fills_candidates)
    single_candidates = single_candidate(candidates, square_coords, sm)
    m, candidates = fill_fit(m,
                             dicts,
                             square_coords,
                             single_candidates=single_candidates)
    return m
def test_fill_fit_single_candidates(medium_sudoku):
    """Test that given single_candidates, the Sudoku is updated correctly and
    the fill is removed from Sudoku dicts."""
    from sudoku_solver_hard import setup, get_missing, fill_fit
    m = medium_sudoku
    c, dicts, square_coords = setup(m)
    rm, cm, sm = dicts
    single_candidates = [(7, (0, 3)), (9, (3, 1)), (6, (5, 0)), (7, (5, 8)),
                         (9, (7, 5)), (2, (8, 3))]
    m = fill_fit(m, dicts, square_coords, single_candidates=single_candidates)
    candidates, dicts, square_coords = setup(m)
    rm, cm, sm = dicts
    assert m[0][3] == 7
    assert m[5][0] == 6
    assert m[8][3] == 2
    assert 7 not in rm[0]
Exemplo n.º 5
0
def test_fill_fit(medium_sudoku, immediate_fills_candidates,
                  immediate_fills_dicts):
    """Test that given candidates with immediate fits, the Sudoku is updated correctly
    and the fill is removed from Sudoku dicts."""
    from sudoku_solver_hard import fill_fit
    m = medium_sudoku
    dicts, square_coords = immediate_fills_dicts
    rm, cm, sm = dicts
    m, candidates = fill_fit(m,
                             dicts,
                             square_coords,
                             candidates=immediate_fills_candidates)
    assert m[4][4] == 3
    assert m[2][4] == 6
    assert m[6][4] == 5
    assert 3 not in rm[4]
    assert (4, 4) not in candidates.keys()