예제 #1
0
def answer(text, opt):
    print('Sudoku sebelum terisi: ')
    if (opt == 1):
        problem = fileToMatrix(text)
        sudoku.printSudoku(problem)
    elif (opt == 0):
        problem = pngToMatrix(text)
        sudoku.printSudoku(problem)

    # Menampilkan jawaban
    print('Sudoku setelah diisi: ')
    if (sudoku.solveSudoku(problem)):
        sudoku.printSudoku(problem)
    else:
        print("Tidak ada solusi")

    print("Koordinat dari area bernomor 5 adalah: ")
    sudoku.findFive(problem)
예제 #2
0
파일: test.py 프로젝트: urska19/LVR-sat
print unicode(true()), "->", solver.solve(true())
print "================================================="
print "sudoku"

board=[[4, 8, None, 1, 6, None, None, None, 7],
 [1, None, 7, 4, None, 3, 6, None, None],
 [3, None, None, 5, None, None, 4, 2, None],
 [None, 9, None, None, 3, 2, 7, None, 4],
 [None, None, None, None, None, None, None, None, None],
 [2, None, 4, 8, 1, None, None, 6, None],
 [None, 4, 1, None, None, 8, None, None, 6],
 [None, None, 6, 7, None, 1, 9, None, 3],
 [7, None, None, None, 9, 6, None, 4, None]]

print printSudoku(board)

import sys
formula = sudoku(board)
# sys.stderr.write( unicode(sudoku(board)[0].nnf().cnf().simplify()).encode("utf-8") )
result = solver.solve(formula)
print printSudoku(processResult(result[1]))



print "================================================="
print "================================================="
print "SAT Solver - mt - Testing"
print "================================================="
solver = SAT_solver()
for i in globals().keys():
예제 #3
0
from sudoku import printSudoku
from sudoku import startSolve

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

printSudoku(sudoku)
solvedSudoku = startSolve(sudoku)
print("************************")
printSudoku(solvedSudoku)
예제 #4
0
# None - empty square.
board = [
    [None, 8, None, 1, 6, None, None, None, 7],
    [1, None, 7, 4, None, 3, 6, None, None],
    [3, None, None, 5, None, None, 4, 2, None],
    [None, 9, None, None, 3, 2, 7, None, 4],
    [None, None, None, None, None, None, None, None, None],
    [2, None, 4, 8, 1, None, None, 6, None],
    [None, 4, 1, None, None, 8, None, None, 6],
    [None, None, 6, 7, None, 1, 9, None, 3],
    [7, None, None, None, 9, 6, None, 4, None],
]

# print sudoku from board definition.
print "Lab exercise:"
print printSudoku(board)

# construct logical formula from board definition.
formula = sudoku(board)

# solve formula using SAT solver(singlethreaded)
result = solver.solve(formula)

print "Solution:"
# process and print result of sat solver.
print printSudoku(processResult(result[1]))

medium_board = [
    [None, None, 5, None, 6, 3, 1, 2, None],
    [None, None, 9, None, None, 1, None, 5, None],
    [1, None, None, None, None, 8, 9, None, 6],