Exemple #1
0
    def count_solutions(self, board, maximum = 100):
        if board.is_valid():
            return 1
        
        self.initialize_vars(board)
        self.goal = lambda solver : solver.done or solver.solutions >= maximum

        start = t.time()
        if not board.is_possible():
            self.done = True

        self.step()
        end = t.time()

        print('Sudoku board solved in ' + str(end - start))
        self.clean_board()
        return self.solutions
Exemple #2
0
    def solve(self, board):
        if board.is_valid():
            return board

        self.initialize_vars(board)
        self.goal = lambda solver : solver.done or solver.board.is_valid()

        start = t.time()
        if not board.is_possible():
            self.done = True

        self.step()
        end = t.time()

        print('Sudoku board solved in ' + str(end - start))

        if self.done:
            return board_impossible()
        else:
            return board