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
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
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))
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