Пример #1
0
 def test_one_empty_square(self):
     test_board = '2564891733746159829817234565932748617128.6549468591327635147298127958634849362715'
     test_solution = '256489173374615982981723456593274861712836549468591327635147298127958634849362715'
     assert len(test_board) == len(test_solution)
     s = Sodoku(test_board)
     s.solve()
     s_solved = s.get_oneline_str()
     assert s_solved == test_solution
Пример #2
0
    def test_naked_singles(self):
        test_board = '3.542.81.4879.15.6.29.5637485.793.416132.8957.74.6528.2413.9.655.867.192.965124.8'
        test_solution = '365427819487931526129856374852793641613248957974165283241389765538674192796512438'

        assert len(test_board) == len(test_solution)
        s = Sodoku(test_board)
        s.solve()
        s_solved = s.board
        assert s_solved == test_solution
Пример #3
0
 def test_hidden_singles(self):
     test_board = '..2.3...8'\
                  '.....8...'\
                  '.31.2....'\
                  '.6..5.27.'\
                  '.1.....5.'\
                  '2.4.6..31'\
                  '....8.6.5'\
                  '.......13'\
                  '..531.4..'
     test_solution = '672435198'\
                     '549178362'\
                     '831629547'\
                     '368951274'\
                     '917243856'\
                     '254867931'\
                     '193784625'\
                     '486592713'\
                     '725316489'
     assert len(test_board) == len(test_solution)
     s = Sodoku(test_board)
     s.solve()
     s_solved = s.get_oneline_str()
     assert s_solved == test_solution
Пример #4
0
def sol3d(grid):
    print(grid[0])
    s = Sodoku("".join(grid[1:]))
    s.solve()
    print(s.board)
    return int(s.board[0:3])
Пример #5
0
from bib.sodoku import Sodoku
from bib.listless import chunks


def sol3d(grid):
    print(grid[0])
    s = Sodoku("".join(grid[1:]))
    s.solve()
    print(s.board)
    return int(s.board[0:3])


def p096():
    with open('../txt_files/p096_sodoku.txt', 'r') as f:
        f_lines = [line.strip('\n') for line in f.readlines()]
    sodoku_boards = [chunk for chunk in chunks(f_lines, 10)]
    return sum(Sodoku("".join(s[1:])).euler_096_three_digit_number()
               for s in sodoku_boards)
    # for s in sodokus:
    #     print(s)


if __name__ == '__main__':
    unsolved = '003020600900305001001806400008102900700000008006708200002609500800203009005010300'
    solved = '483921657967345821251876493548132976729564138136798245372689514814253769695417382'
    test_sodoku = Sodoku(unsolved)
    test_sodoku.solve()
    assert test_sodoku.get_oneline_str() == solved
    ANSWER = p096()
    print("3-DIGIT NUMBERS SUM: {}".format(ANSWER))
Пример #6
0
 def test_row_unsolvable(self):
     test_b = '9..1....4.14.3.8....3....9....7.8..18....3..........3..21....7...9.4.5..5...16..3'
     sodo = Sodoku(test_b)
     with raises(SodokuError):
         sodo.solve()
Пример #7
0
 def test_duplicate_box(self):
     badbox = '..9.7...5..21..9..1...28....7...5..1..851.....5....3.......3..68........21.....87'
     with raises(SodokuError):
         sbb = Sodoku(badbox)
         sbb.solve()
Пример #8
0
 def test_duplicate_row(self):
     badrow = '.4.1..35.............2.5......4.89..26.....12.5.3....7..4...16.6....7....1..8..2.'
     with raises(SodokuError):
         sbr = Sodoku(badrow)
         sbr.solve()
Пример #9
0
 def test_duplicate_col(self):
     badcol = '6.159.....9..1............4.7.314..6.24.....5..3....1...6.....3...9.2.4......16..'
     with raises(SodokuError):
         sbc = Sodoku(badcol)
         sbc.solve()
Пример #10
0
 def test_lt16_cells_given(self):
     # less than 16 values
     test_board = '...........5....9...4....1.2....3.5....7.....438...2......9.....1.4...6..........'
     s = Sodoku(test_board)
     with raises(SodokuError):
         s.solve()
Пример #11
0
 def test_one_cell_given(self):
     # one cell
     test_board = '........................................1........................................'
     s = Sodoku(test_board)
     with raises(SodokuError):
         s.solve()
Пример #12
0
 def test_empty_board(self):
     # empty board
     test_board = '.................................................................................'
     s = Sodoku(test_board)
     with raises(SodokuError):
         s.solve()
Пример #13
0
 def test_already_solved(self):
     test_board = '974236158638591742125487936316754289742918563589362417867125394253649871491873625'
     s = Sodoku(test_board)
     s.solve()
     s_solved = s.get_oneline_str()
     assert s_solved == test_board
Пример #14
0
 def test_square_unsolvable(self):
     test_b = '..9.287..8.6..4..5..3.....46.........2.71345.........23.....5..9..4..8.7..125.3..'
     sodo = Sodoku(test_b)
     with raises(SodokuError):
         # sbc = Sodoku.from_oneline_str(badcol)
         sodo.solve()
Пример #15
0
 def test_box_unsolvable(self):
     test_b = '.9.3....1....8..46......8..4.5.6..3...32756...6..1.9.4..1......58..2....2....7.6.'
     sodo = Sodoku(test_b)
     with raises(SodokuError):
         sodo.solve()
Пример #16
0
 def test_col_unsolvable(self):
     test_b = '....41....6.....2...2......32.6.........5..417.......2......23..48......5.1..2...'
     sodo = Sodoku(test_b)
     with raises(SodokuError):
         sodo.solve()