def main(): width = height = 6 grid = generator.generate_puzzle(width, height) display(width, height, grid) grid = generate_puzzle(width, height, grid) display(width, height, grid) grid = naive.solve(width, height, grid) display(width, height, grid) grid = solver.solve(width, height, grid) display(width, height, grid)
def solve(width, height, grid): grid = naive.solve(width, height, grid) if grid.count(0) == 0: return grid generator = _solve1(width, height, grid) try: result = generator.next() except StopIteration: raise Exception('No solutions exist.') try: generator.next() except StopIteration: return result raise Exception('Multiple solutions exist.')