def solve(): """this function solves the wordseaerch puzzle given and returns the correspondant cell and direction of each word""" self.solveButton.config(state="disabled") self.grid = empty((9, 9), dtype=str) try: for row in range(9): for column in range(9): self.grid[row, column] = int( self.numberStringVar[(row, column)].get()) except: mb.showerror("Entry Error", "Input must be single digit numbers") self.solveButton.config(state="normal") start = time() solver = SudokuSolver(self.grid) try: mb.showinfo( "Loding", "The solving process could take a long time depending on te complexity of the Sudoku grid \nPlease Wait !!!" ) self.grid = solver.solve() for row in range(9): for column in range(9): self.numberStringVar[(row, column)].set( str(self.grid[row, column])) mb.showinfo( "Finished", "The solving process took about " + str(time() - start) + " seconds to finish !!!") except: mb.showerror( "Entry Error", "There is an error in your input, please re-enter a coorect grid" ) self.solveButton.config(state="normal")
def __solve_sudoku(self): self.unsolved_puzzle = copy.deepcopy(self.game.puzzle) #backtracking_solver = BacktrackingSudokuSolver(self.game.puzzle) #backtracking_solver.solve() dlx_sudoku_solver = SudokuSolver(self.game.puzzle) solutions = dlx_sudoku_solver.solve_sudoku() dlx_sudoku_solver.final_solution(solutions) self.__draw_puzzle(dlx_sudoku_solver.solution_board)
def upload_refined(mat): mat = mat.encode('ascii', 'ignore') arr = mat.split(',') arr = [int(e) for e in arr] sud = [arr[i:i + 9] for i in xrange(0, len(arr), 9)] ss = SudokuSolver(sud) global solvedSuds solvedSuds = ss.main() print solvedSuds return url_for('solved')
def solve_step(): board = request.json['board'] sp = SudokuPuzzle(board) ss = SudokuSolver(sp) ss.solve_next_step() log = ss.sudoku_logger.sudoku_log try: return jsonify({'board': ss.sudoku_puzzle.get_board(), 'steps_log': log}) except Exception as e: print(e)
def solve_puzzle(): print(request.json) print(request.json['board']) # params = request.json.to_dict() # print(params) board = request.json['board'] sp = SudokuPuzzle(board) ss = SudokuSolver(sp) ss.do_work() log = ss.sudoku_logger.sudoku_log try: return jsonify({'board': ss.sudoku_puzzle.get_board(), 'steps_log': log}) except Exception as e: print(e)
def assert_expected_solver_output(self, puzzle, expected_done, solution_count, solution=None, constraints=None): puzzle_grid = SudokuGrid(puzzle) my_solution, done, info = SudokuSolver().solveSudoku(puzzle_grid, verbose=False, constraints=constraints) #self.assertEqual(info,"") self.assertEqual(done, expected_done) self.assertEqual(info['solutions'], solution_count) if solution: self.assertTrue(SudokuGrid(solution) == my_solution, msg=f'solution does not match. Actual: {my_solution}')
def main(): """Spreadsheet Column Printer This script allows the user to solve a Sudoku board by specifying the image-path as an argument (with quotation marks), the image needs to contain a Sudoku board. This script works best on image taken on real paper where the Sudoku board takes up almost the whole picture. If no path is specified, a random image will be taken from the folder Example images. This script requires that the following dependencies to be within the Python environment you are running this script in: - keras - tensorflow - numpy - matplotlib - scikit-image This script can also be run in an IDE, but then the user has to manipulate and manually set the image path. """ if len(sys.argv) > 1: image_path = str(sys.argv[1]) else: print("No image specified. Taking a random image.") base_path = os.getcwd() + "\Example images\\" image_path = base_path + os.listdir(base_path)[random.randint(0,len(os.listdir(base_path))-1)] input_sudoku_img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) plt.imshow(input_sudoku_img, cmap='gray') plt.show() resized_sudoku_img = cv2.resize(input_sudoku_img, (1200, 900), interpolation=cv2.INTER_AREA) processed_sudoku_img = preprocess_sudoku_board(resized_sudoku_img.copy(), MNIST_DIMENSION) sudoku_board = np.zeros((9, 9), dtype=np.int8) # Import final model model = load_model(os.path.dirname(os.path.realpath(__file__)) + "\Final model") for index, square in enumerate(processed_sudoku_img): if square[1]: # Normalize number number = square[0] / 255 number = np.reshape(number, newshape=(1, 28, 28, 1)) prediction = model.predict(number)[0] sudoku_board[int(index / 9)][index % 9] = int(np.argmax(prediction)) + 1 else: sudoku_board[int(index / 9)][index % 9] = -1 print("Interpreted the Sudoku to be:") sudoku_solver = SudokuSolver() sudoku_solver.print_board(sudoku_board) if not sudoku_solver.is_valid_board(sudoku_board): print("Sorry, no solution was found. Take a new picture and try again.") quit() solved_sudoku = np.array(sudoku_solver.solve(sudoku_board)[0]) sudoku_solver.print_board(solved_sudoku)
def click(): def new_int(t): return int(t) if t else 0 grid = [ list(new_int(t.get()) for t in self.texts[i * 9:i * 9 + 9]) for i in range(9) ] s = SudokuSolver(grid) r = s.solve() if r.startswith('+'): lbs = [ list(t for t in labels[i * 9:i * 9 + 9]) for i in range(9) ] for i in range(9): for j in range(9): lbs[i][j].config(text=s.b[i][j]) else: mb.showerror(message=r)
def main(): # board = save_and_get_new_board(4) # print(board) # board = read_saved_board(11) board = [ [None, None, 7, 4, None, None, 3, None, None], [None, None, None, None, 7, None, None, None, 8], [9, 2, None, None, None, None, None, None, None], [6, None, None, 9, 1, 3, 8, None, 2], [None, 8, 3, None, None, 4, 6, None, None], [2, None, None, 8, None, None, None, None, None], [3, None, 8, 1, None, None, None, None, None], [None, 9, None, 3, None, None, None, None, 4], [1, None, None, None, None, 6, None, None, None] ] sp = SudokuPuzzle(board) # sp.print_board() ss = SudokuSolver(sp) ss.do_work()
def solve_puzzle(): try: board = request.json['board'] puzzle_name = request.json['puzzleName'] # Check if the puzzle has a solution validate_puzzle(puzzle_name, board) sp = SudokuPuzzle(board) ss = SudokuSolver(sp) ss.do_work() log = ss.sudoku_logger.sudoku_log return jsonify({ 'success': True, 'board': ss.sudoku_puzzle.get_board(), 'steps_log': log }) except Exception as e: print(e) return jsonify({ 'success': False })
def Main(): puzzles = ParsePuzzleStrings() keySum = 0 startTime = time() for puzzle in puzzles: board = puzzle[1] trials = 0 solver = SudokuSolver(board, yieldLevel=0) generator = solver.Generate() for result in generator: # result = next(generator) trials += 1 if result == 2: line = solver.board[0] key = line[0] * 100 + line[1] * 10 + line[2] keySum += key print( "After {} trials, we found a solution for {} with a key: {}" .format(trials, puzzle[0], key)) endTime = time() print("After {} seconds, the final sum of keys is {}".format( endTime - startTime, keySum))
def _calc_solution(self, cells_entry): solutions_queue = Queue() def process_queue(): try: sols = solutions_queue.get(0) self._draw_solution(sols) except Empty: self._root.after(100, lambda: process_queue()) ss = SudokuSolver() for i in range(0, 9): for j in range(0, 9): value = cells_entry[i][j].get() if value: ss.add_known_number(i + 1, j + 1, int(value)) ResolutionThread(solutions_queue, ss).start() self._waiting() self._root.after(100, lambda: process_queue())
def main(): ss = SudokuSolver() print "Algorithm is running..." print "Running time limit: 5 mins" # Imp 1 #ss.printBoard(ss.getBoard("sudoku9_1.txt")) # Imp 2 #print ss.isValid(ss.getBoard("sudoku4_1.txt")) # Imp 3 #if ss.SA_solver2(ss.getBoard("sudoku9_9.txt")) != False: # ss.printBoard(ss.board) # print "Conflicts:",ss.isValid(ss.board) # print "Time used:",int(ss.e_time),"secs" #else: # print "No solution found." # Imp 4 #if ss.AS_solver(ss.getBoard("sudoku9_8.txt")) == True: # ss.printBoard(ss.board) # print "Conflicts:",ss.isValid(ss.board) # print "Time used:",int(ss.e_time),"secs" #else: # print "No solution found." # Imp 5 if ss.CSP_solver(ss.getBoard("sudoku9_8.txt")) == True: ss.printBoard(ss.board) print "Conflicts:",ss.isValid(ss.board) print "Time used:",int(ss.e_time),"secs" else: print "No solution found."
def generate_puzzle(iterations): solution = SudokuBoard() solution.build() playable = solution.clone() difficult_coefficient = 1 for _ in range(iterations): new_playable = playable.clone() row_num, column_num = random.randrange(9), random.randrange(9) while new_playable.is_cell_empty(row_num, column_num): row_num, column_num = random.randrange(9), random.randrange(9) new_playable.clear_cell(row_num, column_num) solver = SudokuSolver(new_playable) try: solver.solve() playable = new_playable difficult_coefficient = solver.difficult_coefficient except: continue difficult_level = None if difficult_coefficient < DifficultLevel.VERY_EASY.value: difficult_level = DifficultLevel.VERY_EASY elif difficult_coefficient < DifficultLevel.EASY.value: difficult_level = DifficultLevel.EASY elif difficult_coefficient < DifficultLevel.MEDIUM.value: difficult_level = DifficultLevel.MEDIUM elif difficult_coefficient < DifficultLevel.HARD.value: difficult_level = DifficultLevel.HARD elif difficult_coefficient < DifficultLevel.VERY_HARD.value: difficult_level = DifficultLevel.VERY_HARD elif difficult_coefficient < DifficultLevel.MASTER.value: difficult_level = DifficultLevel.MASTER return SudokuGame(playable, solution, difficult_level, difficult_coefficient)
def __init__(self, parent=None): self.solver = SudokuSolver() QWidget.__init__(self, parent) self.errors = dict() gbox = QGridLayout() c1 = QGraphicsView() color = QtGui.QColor(0) color.setBlue(255) gradient = QtGui.QRadialGradient(0, 0, 10) gradient.setSpread(QtGui.QGradient.RepeatSpread) c1.setForegroundBrush(color) c1.setPalette(QtGui.QPalette(QtGui.QColor(250, 250, 200))) c1.setAutoFillBackground(True) enter = QPushButton("Solve") enter.setMaximumHeight(40) enter.clicked.connect(self.solve) clear = QPushButton("Clear") clear.setMaximumHeight(40) clear.clicked.connect(self.clear) self.label = QLabel() self.squares = SquareWidget() gbox.addWidget(self.squares, 0, 0) hbox = QHBoxLayout() gbox.addWidget(self.label, 1, 0) hbox.addWidget(clear) hbox.addWidget(enter) gbox.addLayout(hbox, 2, 0, alignment=Qt.AlignRight) self.setLayout(gbox)
class Main: image = ImageDigitReader() sudoku_board_img = image.get_sudoku_board() sudoku_board = [ [4, 1, 7, 0, 0, 0, 5, 0, 0], [5, 0, 0, 0, 6, 0, 4, 2, 0], [0, 6, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 9, 0, 0, 3, 7, 0], [1, 5, 3, 0, 7, 2, 0, 8, 0], [0, 0, 0, 3, 0, 8, 6, 0, 0], [9, 2, 8, 7, 0, 0, 1, 4, 3], [0, 0, 5, 0, 9, 0, 8, 0, 0], [6, 0, 1, 4, 0, 0, 2, 9, 5] ] sudoku = SudokuSolver(sudoku_board_img) sudoku.print_solved_sudoku()
#!/usr/bin/env python from SudokuSolver import SudokuSolver import sys s = SudokuSolver('sudoku/example.sdk') s.parseBoard() s.printBoard() s.onlyValid(0,0) s.printBoard()
t = Tester() i = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 0, 0, 0, 8, 0, 0, 7, 9], ] t.test(i, True, SudokuSolver().solve(i)) i = [ [1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], ] t.test(i, True, SudokuSolver().solve(i)) i = [
button_text_rect = button_text.get_rect() button_text_rect.center = solve_button.center self.screen.blit(button_text, button_text_rect.topleft) print('Button clicked!') solver.solve_board() gui = Gui() solver = SudokuSolver([[0, 0, 0, 0, 1, 0, 9, 2, 0], [0, 0, 0, 4, 9, 3, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 7, 0], [6, 0, 0, 0, 0, 0, 3, 0, 0], [0, 5, 0, 0, 0, 0, 0, 0, 0], [0, 1, 3, 0, 0, 0, 0, 6, 8], [0, 0, 2, 9, 0, 0, 7, 3, 0], [4, 0, 0, 0, 0, 0, 0, 0, 5], [5, 0, 8, 0, 0, 7, 0, 0, 0]], gui) gui.start(solver) solver.solve_board() # Easy # [[0, 4, 0, 0, 0, 2, 0, 1, 9], # [0, 0, 0, 3, 5, 1, 0, 8, 6], # [3, 1, 0, 0, 9, 4, 7, 0, 0], # [0, 9, 4, 0, 0, 0, 0, 0, 7], # [0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 8], [5, 0, 0, 0, 4, 0, 0, 0, 9], [7, 0, 0, 0, 0, 0, 0, 6, 0], [4, 0, 0, 0, 0, 0, 7, 0, 0], [0, 2, 0, 0, 0, 6, 0, 0, 0], [0, 0, 3, 9, 8, 0, 0, 0, 0] ] input=np.array(input) self=board.SudokuBoard(input) #self.getPossibleValues(0,0) self=solver.SudokuSolver(self) # # self.solve() # # self.board.isBoardComplete() # # self.board.isBoardValid() # # self.board.board import SudokuSolver.SudokuBoardMiracle as boardMiracle input =[ [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0],
from SudokuSolver import SudokuSolver from NumberRecognizer import NumberRecognizer from SudokuAlgorithm import SudokuAlgorithm import cv2 recognizer = NumberRecognizer('./deeplearning/models/cnn/best_model') solver = SudokuSolver(recognizer) paths = [ "./inputs/c.jpg", "./inputs/d.jpg", "./inputs/e.jpg", "./inputs/g.jpg", "./inputs/n.png", "./inputs/o.png", "./inputs/p.png", "./inputs/q.png", "./inputs/r.png", "./inputs/s.png", "./inputs/v.png", "./inputs/u.png", ] for path in paths: try: img, grid = solver.imageToGrid(cv2.imread(path)) img = cv2.resize(img, (600, 600)) h, w, ch = img.shape if grid != None: algorithm = SudokuAlgorithm(grid)
) args = parser.parse_args() conflictPuzzlesPath = 'conflictPuzzles.txt' conflictTranscriptsPath = 'conflictTranscripts.txt' # Count the number of lines in the file if not isfile(args.sudokuPuzzlesFile): print('Cannot open', args.sudokuPuzzlesFile) exit(1) totalCount = sum(1 for line in open(args.sudokuPuzzlesFile)) # Load the Sudoku puzzles from the Ruud test set and try to solve them solver = SudokuSolver() solvedCount = 0 unsolvedCount = 0 conflictCount = 0 fConflictPuzzles = open(conflictPuzzlesPath, 'w') fConflictTranscripts = open(conflictTranscriptsPath, 'w') with open(args.sudokuPuzzlesFile, 'r') as f: puzzleString = f.readline().strip() pbar = ProgressBar(widgets=['Evaluating: ', Percentage(), ' ', Bar(), ' ', ETA()]) pbar.start(max_value=totalCount) i = 0
import os ## Next few lines to uncomment if there is a problem with CUDA #os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" # see issue #152 #os.environ["CUDA_VISIBLE_DEVICES"] = "-1" from keras.models import load_model from SudokuSolver import SudokuSolver fileName = 'Sudoku_test.png' filePath = os.getcwd()+'\\ressources\\SudokuImages\\'+fileName savePath = os.getcwd()+'\\ressources\\ResultsImages\\solution_'+fileName digitImagesDirectory = os.getcwd()+'\\ressources\\digitSamples' model_name = 'digitsModel.h5' if __name__ == "__main__": model = load_model(model_name) solver = SudokuSolver(model, filePath, True, savePath, digitImagesDirectory) print("\nSudoku Solved")
def SolverFromPuzzleNumber(self, number): board = puzzles[number][1] return SudokuSolver(board, yieldLevel=0)
def SolverFromDifficulty(self): if self.difficulty == Difficulty.Easy: board = easyBoard else: board = hardBoard return SudokuSolver(board, yieldLevel=0)
#medium game # game_board = [[4, 0, 0, 0, 0, 0, 0, 2, 0], # [8, 0, 0, 7, 0, 9, 0, 0, 0], # [0, 1, 6, 3, 0, 0, 0, 0, 0], # [5, 0, 9, 0, 0, 0, 0, 1, 0], # [3, 7, 4, 2, 0, 1, 5, 8, 6], # [0, 8, 0, 0, 0, 0, 7, 0, 9], # [0, 0, 0, 0, 0, 7, 6, 3, 0], # [0, 0, 0, 8, 0, 5, 0, 0, 4], # [0, 9, 0, 0, 0, 0, 0, 0, 7]] # #Hard game # game_board = [[5, 9, 0, 0, 0, 7, 0, 8, 0], # [0, 0, 0, 5, 0, 0, 0, 0, 7], # [4, 1, 0, 8, 0, 0, 5, 0, 6], # [0, 0, 1, 3, 0, 0, 0, 0, 4], # [0, 0, 5, 0, 0, 0, 9, 0, 0], # [8, 0, 0, 0, 0, 4, 2, 0, 0], # [9, 0, 2, 0, 0, 3, 0, 4, 5], # [1, 0, 0, 0, 0, 5, 0, 0, 0], # [0, 5, 0, 4, 0, 0, 0, 6, 9]] game = SudokuSolver() root = Tk() sudokuUI = SudokuUI(root, game) root.geometry("%dx%d" % (WIDTH, HEIGHT + 150)) #Extra 200 to add extra attributes root.mainloop()
image_container = ImagePrepper(settings.FILE_NAME) except: if settings.VERBOSE_EXIT: print("ERROR -- Failed to load image. Does the image " "exist? Do you have a typo? Note: only .png, .jpg and " ".jpeg files are supported.") exit() if settings.ENABLE_DEBUG: print("DEBUG GLOBAL -- Image succesfully loaded.") print("DEBUG GLOBAL -- Attempting to extract values from image.") # Show preview if enabled in the settings if settings.ENABLE_PREVIEW or settings.ENABLE_PREVIEW_ALL: image_preview(image_container.image) extracted_info = ImageExtractor(image_container.image) sudoku_solver = SudokuSolver(extracted_info.starting_grid) board_is_valid = sudoku_solver.board_is_valid() if not board_is_valid: if settings.VERBOSE_EXIT: print("ERROR -- Starting values found in sudoku were not valid.") print("The following board was found: ") sudoku_solver.print_sudoku() exit() if settings.ENABLE_DEBUG: print("DEBUG -- Following starting board was found: ") sudoku_solver.print_sudoku() if settings.ENABLE_DEBUG: print("DEBUG -- Attempting to solve the sudoku.")
t = Tester() i = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 0, 0, 0, 8, 0, 0, 7, 9], ] t.test(i, True, SudokuSolver().solve(copy.deepcopy(i))) i = [ [1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], ] t.test(i, True, SudokuSolver().solve(copy.deepcopy(i))) i = [
WIDTH = 630 HEIGHT = 730 pygame.init() window = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption('Sudoku') pygame.display.set_icon(pygame.Surface((32, 32))) # Sudoku values numbers = SpriteSheet("sudoku_numbers.png") images = SpriteSheet("button_sprites.png") sudoku = SudokuSolver() board_num = 0 selected_tile = None # Sudoku grid buttons = [] buttons.append(Button((15, 15), (70, 70), images.get_num(3), prev_board)) buttons.append(Button((545, 15), (70, 70), images.get_num(2), next_board)) buttons.append(Button((175, 15), (70, 70), images.get_num(1), solve_board)) buttons.append( Button((630 - 175 - 70, 15), (70, 70), images.get_num(0), reset_board)) tiles = set_board(sudoku.board) lines = []
class SudokuWidget(QtWidgets.QWidget): boardText = "" valueChanged = QtCore.pyqtSignal(bool) def __init__(self, parent=None): self.solver = SudokuSolver() QWidget.__init__(self, parent) self.errors = dict() gbox = QGridLayout() c1 = QGraphicsView() color = QtGui.QColor(0) color.setBlue(255) gradient = QtGui.QRadialGradient(0, 0, 10) gradient.setSpread(QtGui.QGradient.RepeatSpread) c1.setForegroundBrush(color) c1.setPalette(QtGui.QPalette(QtGui.QColor(250, 250, 200))) c1.setAutoFillBackground(True) enter = QPushButton("Solve") enter.setMaximumHeight(40) enter.clicked.connect(self.solve) clear = QPushButton("Clear") clear.setMaximumHeight(40) clear.clicked.connect(self.clear) self.label = QLabel() self.squares = SquareWidget() gbox.addWidget(self.squares, 0, 0) hbox = QHBoxLayout() gbox.addWidget(self.label, 1, 0) hbox.addWidget(clear) hbox.addWidget(enter) gbox.addLayout(hbox, 2, 0, alignment=Qt.AlignRight) self.setLayout(gbox) def clear(self): self.squares.arr = [[0 for x in range(9)] for y in range(9)] self.squares.update() def solve(self): err_dict, err_str = self.solver.solve_set(self.squares.getArrStr()) self.squares.arr = self.solver.board.get_board() ltext = "" if err_dict is not None: err = err_dict.popitem() if err[1] == Sudoku.Board.ERRORS_BLK: ltext = "Block" elif err[1] == Sudoku.Board.ERRORS_ROW: ltext = "Row" elif err[1] == Sudoku.Board.ERRORS_COL: ltext = "Col" ltext += " error at " + str(err[0]) self.label.setText(ltext) self.squares.update()
from SudokuSolver import SudokuSolver obj = SudokuSolver() grid = obj.readSudoku() obj.solve(grid)
from SudokuSolver import SudokuSolver import os import json solver = SudokuSolver() rules = solver.get_rules(9) probs = [] for i in range(1, 81): folder = 'data/' + str(i) + '/' total = 100 counter = 0 for filename in os.listdir(folder): if 'puzzle' in filename: counter += 1 if solver.is_proper(solver.sudoku_to_cnf(folder + filename) + rules) else 0 prob = counter/total probs.append({'givens': i, 'prob': prob}) with open('properness_probs.json', 'w') as fp: json.dump({'data': probs}, fp)
from CheckNumber import checkIfNumberOk from SudokuGen import SudokuGenerator from SudokuSolver import SudokuSolver print('generating...') s1 = SudokuGenerator() sudoku1 = s1.getSudokuArray(9, 0.3) print(sudoku1) print('start solving...') s = SudokuSolver() print(s.solve(sudoku1))
def get_solution(puzzle_name, board): print("ACTUALLY SOLVING") sp = SudokuPuzzle(board) ss = SudokuSolver(sp) ss.do_work() return ss.sudoku_puzzle.get_board()