本文整理汇总了Python中sudoku.Sudoku.solve_backtrack方法的典型用法代码示例。如果您正苦于以下问题:Python Sudoku.solve_backtrack方法的具体用法?Python Sudoku.solve_backtrack怎么用?Python Sudoku.solve_backtrack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sudoku.Sudoku
的用法示例。
在下文中一共展示了Sudoku.solve_backtrack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from sudoku import Sudoku [as 别名]
# 或者: from sudoku.Sudoku import solve_backtrack [as 别名]
#!/usr/bin/env python
#coding:utf-8
from sudoku import Sudoku
# Reading of sudoku list from file
try:
f = open("sudokus.txt", "r")
sudokuList = f.read()
except:
print "Error in reading the sudoku file."
exit()
# 1.5 count number of sudokus solved by AC-3
num_ac3_solved = 0
for line in sudokuList.split("\n"):
s = Sudoku(line)
if s.solve_ac3():
num_ac3_solved += 1
s.print_sudoku()
else:
print "Failed to solve using AC-3"
print "Solved %d sudokus using AC-3 inference" % num_ac3_solved
# 1.6 solve all sudokus by backtracking
for line in sudokuList.split("\n"):
s = Sudoku(line)
if s.solve_backtrack():
s.print_sudoku()
else:
print "Failed to solve using backtrack"