本文整理匯總了Python中Solver.test_cell方法的典型用法代碼示例。如果您正苦於以下問題:Python Solver.test_cell方法的具體用法?Python Solver.test_cell怎麽用?Python Solver.test_cell使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Solver
的用法示例。
在下文中一共展示了Solver.test_cell方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: number_solutions
# 需要導入模塊: import Solver [as 別名]
# 或者: from Solver import test_cell [as 別名]
def number_solutions(copy_s, row, col):
num_solutions = 0
if row == 8 and col == 8:
return num_solutions + 1
if col == 9:
row = row + 1
col = 0
if copy_s[row][col] == 0:
present = Solver.test_cell(copy_s, row, col)
if 0 not in present:
return 0
while 0 in present:
copy_s[row][col] = present.index(0)
present[present.index(0)] = 1
num_solutions += number_solutions(copy_s, row, col + 1)
copy_s[row][col] = 0
return num_solutions
num_solutions += number_solutions(copy_s, row, col + 1)
return num_solutions
示例2: fill_sudoku
# 需要導入模塊: import Solver [as 別名]
# 或者: from Solver import test_cell [as 別名]
def fill_sudoku(s, row, col):
if row == 8 and col == 8:
present = Solver.test_cell(s, row, col)
s[row][col] = present.index(0)
return True
if col == 9:
row = row + 1
col = 0
sequence = [1, 2, 3, 4, 5, 6, 7, 8, 9]
random.shuffle(sequence)
for i in range(9):
s[row][col] = sequence[i]
if valid_cell(s, row, col):
if fill_sudoku(s, row, col + 1):
return True
s[row][col] = 0
return False