def main(): """ main program, solves a users sudoku puzzle :return: n/a """ pz = puzzle.get_puzzle(0) solver = Solver(pz) puzzle.pretty_print_puzzle(pz) solver.solve_puzzle() puzzle.pretty_print_puzzle(pz)
def get_or_create_zone_path(zone_path): zone_path = ZonePath.clean(zone_path) cur_zone_obj = DbQueries.find_by_zone_path_or_null(zone_path) if cur_zone_obj is not None: return cur_zone_obj new_zone = puzzle.get_puzzle( zone_path, width=config.PUZZLE_WIDTH, height=config.PUZZLE_HEIGHT, ) new_zone['zone_path'] = zone_path new_zone['solved'] = False DbQueries.insert_new_zone(new_zone) return DbQueries.find_by_zone_path_or_null(zone_path)
def __init__(self, rows, cols, width, height, diff): self.rows = rows self.cols = cols self.width = width self.height = height self.diff = diff # Calling get_puzzle function to extract puzzle from sudoku website according to difficulty self.grid = get_puzzle(diff) # Initializing list of Cube objects with the grid values self.cubes = [[ Cube(self.grid[i][j], i, j, self.width, self.height) for j in range(self.cols) ] for i in range(self.rows)] self.model = None self.selected = None self.auto = False
import numpy as np import puzzle board = puzzle.get_puzzle() print('Problem: ') print(board) # a mask that is used to retain info about # which values were an original part of the problem editable = (board == 0) def is_safe_to_insert(n, i, j, board): # checking rows and cols if n in board[i, :] or n in board[:, j]: return False # checking its corresponding 3x3 block # e.g. if i=2, j=8 # board[0:3, 6:9] will be checked row_start, col_start = 3 * (i // 3), 3 * (j // 3) if n in board[row_start:row_start + 3, col_start:col_start + 3]: return False return True # init spot number on the board spot = 0 moving_backwards = False
def _get_puzzle(puznum): return puzzle.get_puzzle(puznum)