def solve_puzzle(puzzle, solve_method): """Solves the puzzle using the given solution method and returns the approximate time taken in seconds.""" start_time = time() result = puzzle.solve_with(solve_method) if result: print(puzzle) else: print("Failed to find the solution.") return time() - start_time if __name__ == '__main__': python_file = '../solutions/p6_solver.py' if len( sys.argv) < 2 else sys.argv[1] method_name = 'backtracking_search' if len(sys.argv) < 3 else sys.argv[2] sys.path.append(os.path.abspath(os.path.dirname(python_file))) module = __import__(os.path.splitext(os.path.basename(python_file))[0]) solve_method = getattr(module, method_name) puzzle = Futoshiki(sys.stdin.read().strip()) start_time = time() result = puzzle.solve_with(solve_method) if result: print(puzzle) else: print("Failed to find the solution.") print("Took %s seconds." % (time() - start_time))