本文整理汇总了Python中sudoku.Sudoku.is_consistent方法的典型用法代码示例。如果您正苦于以下问题:Python Sudoku.is_consistent方法的具体用法?Python Sudoku.is_consistent怎么用?Python Sudoku.is_consistent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sudoku.Sudoku
的用法示例。
在下文中一共展示了Sudoku.is_consistent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sudoku_class
# 需要导入模块: from sudoku import Sudoku [as 别名]
# 或者: from sudoku.Sudoku import is_consistent [as 别名]
#.........这里部分代码省略.........
puzzles_inconsistent.append(
"005079003" # first box inconsistent
"280000000"
"348000000"
"050680000"
"070204080"
"000013020"
"000000471"
"000000006"
"800790300"
)
puzzles_inconsistent.append(
"005079003" # middle box inconsistent
"200000000"
"348000000"
"050680000"
"070264080"
"000013020"
"000000471"
"000000006"
"800790300"
)
puzzles_inconsistent.append(
"005079003" # last row inconsistent
"200000000"
"348000000"
"050680000"
"070204080"
"000013020"
"000000471"
"000000006"
"800790308"
)
puzzles_inconsistent.append(
"005079003" # last col inconsistent
"200000000"
"348000000"
"050680000"
"070204080"
"000013026"
"000000471"
"000000006"
"800790300"
)
srtestpuzzle = ( # puzzle for the subregion test
"665679663" "266666666" "348666666" "656686666" "676264686" "666613626" "666666471" "666666666" "866796366"
)
for puzzle in puzzles_corrupt: # corrupt puzzles test
try:
Sudoku(instr=puzzle)
except SudokuInputError:
pass
else:
raise Exception("Bad input accepted")
for incons in puzzles_inconsistent: # inconsistent puzzles test
sudoku = Sudoku(instr=incons)
sudoku.solve()
assert not sudoku.is_consistent()
sudoku = Sudoku(instr=validpuzzle) # OK, let's see a valid puzzle
print sudoku
sudoku.solve()
print sudoku
assert sudoku.is_consistent()
print "human readable: \n{!s}".format(sudoku)
print "repr: \n {!r}".format(sudoku)
print "sudoku.regions: \n{}".format(sudoku.regions)
print "OK. Let's see how fast we can solve some puzzle collections."
# 50 easy, 95 hard
benchmarklist = [
("50 puzzles from Project Euler", "puzzles/euler_puzzles_50.txt", "puzzles/euler_solutions_50.txt"),
("95 hard puzzles", "puzzles/hard_puzzles_95.txt", "puzzles/hard_solutions_95.txt"),
]
# 5 hard
# benchmarklist = [("5 hard puzzles", "puzzles/hard_puzzles_5.txt", "puzzles/hard_solutions_5.txt") ] # for quick profiling
# 50 easy
# benchmarklist = [ ("50 puzzles from Project Euler", "puzzles/euler_puzzles_50.txt", "puzzles/euler_solutions_50.txt")]
for collection_name, path_puzzle, path_solution in benchmarklist:
print collection_name
with open(path_puzzle) as puzzles, open(path_solution, "w") as solutions:
before = time.clock()
collection = SudokuCollection(puzzles)
collection.solve_all(solutions, verbose=True) # TODO make verbosity a command line parameter
puzzleno = len(collection.sudokus) # number of sudokus, TODO: implement API
after = time.clock()
elapsed = after - before
average = elapsed / puzzleno
print "Solving {!s} puzzles took {!s} secs, avg: {!s} sec".format(
puzzleno, elapsed, average
) # TODO check results
print "Tests succesful!"
return True