Beispiel #1
0
from sudoku import create, display
pu, sol = create('hard')
display(pu)
print()
display(sol)
Beispiel #2
0
def evaluatePerformance():
    import cProfile
    global SDStr
    cProfile.run("Shudu(\"%s\").scanSDL()" % SDStr[1])        
    t=Shudu(SDStr[1])
    t.scanSDL()
    for i in range(0,81,9):
        print( t.sdList[i:i+9])
    
      
    cProfile.run("solve(\"%s\")" % SDStr[1])       
                   
def evaluateRunTime():
    global SDStr
    from timeit import Timer
    for SDL in SDStr:     
        print( SDL)
        t1 = Timer("Shudu(\"%s\").scanSDL()" % SDL, "from __main__ import Shudu")
        print( sum(t1.repeat(10, 1))/10)
    print( "==================================")
    for SDL in SDStr:
        SDL.replace("0", ".")
        print( SDL)
        t1 = Timer("solve(\"%s\")" % SDL, "from sudoku import solve")
        print( sum(t1.repeat(10, 1))/10)
    
if __name__ == '__main__' :
    evaluatePerformance()
    evaluateRunTime()
    sudoku.display(sudoku.solve("800000000003600000070090200050007000000045700000100030001000068008500010090000400"))        
Beispiel #3
0
def solve(SDL):
    sudoku.display(sudoku.solve(SDL))
Beispiel #4
0
 def display_solution(self):
     if self._solution is None:
         raise Exception('no puzzles solved yet')
     else:
         sudoku.display(self._solution)
#facile
##var_init = [[3,0,9,0,0,0,6,1,0],[0,0,0,6,0,0,0,7,3],[0,0,0,0,2,8,0,0,4],[0,0,4,0,6,2,5,0,0],[0,7,8,0,4,0,1,2,0],[0,0,2,8,5,0,4,0,0],[4,0,0,5,9,0,0,0,0],[8,9,0,0,0,6,0,0,0],[0,5,3,0,0,0,2,0,1]]
#moyen
##→var_init = [[0,3,0,0,0,0,7,6,2],[0,0,0,3,9,0,0,0,0],[0,8,0,0,0,4,5,0,0],[0,0,0,0,7,0,6,0,0],[1,2,0,0,5,0,0,7,8],[0,0,4,0,3,0,0,0,0],[0,0,6,2,0,0,0,8,0],[0,0,0,0,6,1,0,0,0],[2,4,7,0,0,0,0,5,0]]
#difficile
##var_init = [[6,0,0,5,0,0,0,0,0],[1,5,0,0,0,0,0,9,8],[3,7,0,9,0,0,0,0,0],[0,0,6,3,7,0,4,0,9],[0,0,0,0,0,0,0,0,0],[4,0,5,0,2,9,8,0,0],[0,0,0,0,0,6,0,8,5],[8,2,0,0,0,0,0,1,6],[0,0,0,0,0,1,0,0,4]]
##the hardest
var_init = [[8, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 6, 0, 0, 0, 0, 0],
            [0, 7, 0, 0, 9, 0, 2, 0, 0], [0, 5, 0, 0, 0, 7, 0, 0, 0],
            [0, 0, 0, 0, 4, 5, 7, 0, 0], [0, 0, 0, 1, 0, 0, 0, 3, 0],
            [0, 0, 1, 0, 0, 0, 0, 6, 8], [0, 0, 8, 5, 0, 0, 0, 1, 0],
            [0, 9, 0, 0, 0, 0, 4, 0, 0]]
var1 = copy.deepcopy(var_init)

sudoku.display(var_init)
deterministic_resolve(var1)
sudoku.display(var1)

res = sudoku_stats.is_filled(var1)
print("sudoku filled-in ? --> ", res)

cnt = 1

while res == False:
    print("Iteration " + str(cnt))
    cnt = cnt + 1
    print("Empty cells in lines")
    print(sudoku_stats.get_empty_cells_lines(var1))
    print("Empty cells in rows")
    print(sudoku_stats.get_empty_cells_rows(var1))
Beispiel #6
0
import sudoku

puzzle =    [[0,0,0,0,0,0,0,0,7],
             [8,7,0,0,2,0,0,0,6],
             [9,0,0,0,1,6,0,2,8],
             [2,0,0,9,8,0,6,7,4],
             [0,0,6,1,0,2,8,0,0],
             [4,8,9,0,7,5,0,0,3],
             [5,2,0,4,3,0,0,0,9],
             [6,0,0,0,9,0,0,8,1],
             [1,0,0,0,0,0,0,0,0]]

sudoku.display(puzzle)
print("\n")
output = sudoku.solve(puzzle)
sudoku.display(output)
Beispiel #7
0
 def display_solution(self):
     if self._solution is None:
         raise Exception('no puzzles solved yet')
     else:
         sudoku.display(self._solution)
Beispiel #8
0
# <editor-fold desc = "To do list">
# TODO try to minimize unnecessary calls to eliminate
# TODO make functions for each separate technique
# </editor-fold>

# <editor-fold desc = "Directory management and check import">
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
import sudoku, logic
def check(x)
    """
    Takes puzzle as input and returns solution provided by sudoku.py
    Both are represented by a string.
    """
    return sudoku.display(sudoku.solve(sudoku.initialize_board(x)))
# </editor-fold>

# <editor-fold desc = "Miscellaneous functions to help with readability">

n = 9

def initialize_basis(n):
    global digits = np.arange(n**2)
    global squares = np.arange(n)
    global rows = []
    global squares = set(squares)


def element_q(element, set):
    return element == element & set
Beispiel #9
0
def solve(SDL):
    sudoku.display(sudoku.solve(SDL))
Beispiel #10
0
    t.scanSDL()
    for i in range(0, 81, 9):
        print(t.sdList[i:i + 9])

    cProfile.run("solve(\"%s\")" % SDStr[1])


def evaluateRunTime():
    global SDStr
    from timeit import Timer
    for SDL in SDStr:
        print(SDL)
        t1 = Timer("Shudu(\"%s\").scanSDL()" % SDL,
                   "from __main__ import Shudu")
        print(sum(t1.repeat(10, 1)) / 10)
    print("==================================")
    for SDL in SDStr:
        SDL.replace("0", ".")
        print(SDL)
        t1 = Timer("solve(\"%s\")" % SDL, "from sudoku import solve")
        print(sum(t1.repeat(10, 1)) / 10)


if __name__ == '__main__':
    evaluatePerformance()
    evaluateRunTime()
    sudoku.display(
        sudoku.solve(
            "800000000003600000070090200050007000000045700000100030001000068008500010090000400"
        ))