当前位置: 首页>>代码示例>>Python>>正文


Python Solver.is_valid方法代码示例

本文整理汇总了Python中solver.Solver.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.is_valid方法的具体用法?Python Solver.is_valid怎么用?Python Solver.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在solver.Solver的用法示例。


在下文中一共展示了Solver.is_valid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_is_valid_return_false_when_two_of_same_number_in_block

# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import is_valid [as 别名]
 def test_is_valid_return_false_when_two_of_same_number_in_block(self):
     puzzle = [
                 [
                     Square(1,1,1,1),
                     Square(None,1,2,1),
                     Square(None,1,3,2),
                     Square(None,1,4,2)
                 ],
                 [
                     Square(None,2,1,1),
                     Square(1,2,2,1),
                     Square(None,2,3,2),
                     Square(None,2,4,2)
                 ],
                 [
                     Square(None,3,1,3),
                     Square(None,3,2,3),
                     Square(None,3,3,4),
                     Square(None,3,4,4)
                 ],
                 [
                     Square(None,4,1,3),
                     Square(None,4,2,3),
                     Square(None,4,3,4),
                     Square(None,4,4,4)
                 ]
             ]
     solver = Solver()
     self.assertFalse(solver.is_valid(puzzle))
开发者ID:chriszimmerman,项目名称:python_month,代码行数:31,代码来源:solver_test.py

示例2: test_is_valid

# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import is_valid [as 别名]
 def test_is_valid(self):
     puzzle = [
                 [
                     Square(1,1,1,1),
                     Square(4,1,2,1),
                     Square(3,1,3,2),
                     Square(2,1,4,2)
                 ],
                 [
                     Square(3,2,1,1),
                     Square(2,2,2,1),
                     Square(4,2,3,2),
                     Square(1,2,4,2)
                 ],
                 [
                     Square(4,3,1,3),
                     Square(1,3,2,3),
                     Square(2,3,3,4),
                     Square(3,3,4,4)
                 ],
                 [
                     Square(2,4,1,3),
                     Square(3,4,2,3),
                     Square(1,4,3,4),
                     Square(4,4,4,4)
                 ]
             ]
     solver = Solver()
     self.assertTrue(solver.is_valid(puzzle))
开发者ID:chriszimmerman,项目名称:python_month,代码行数:31,代码来源:solver_test.py

示例3: len

# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import is_valid [as 别名]
import sys
from solver import Solver
from file_reader import FileReader

if len(sys.argv) != 2:
    print("Please specify a puzzle file to solve.")
    sys.exit(0)

filename = sys.argv[1]
file_reader = FileReader()

puzzle = file_reader.get_puzzle_from_file(filename)

solver = Solver()

if solver.is_valid(puzzle):
    print('Okay, I can solve this.')
    solution = solver.solve(puzzle)

    for row in solution:
        for square in row:
            print(str(square.number) + ' ', end='')
        print('\n', end='')
else:
    print('This puzzle is invalid.')
    
开发者ID:chriszimmerman,项目名称:python_month,代码行数:27,代码来源:__init__.py


注:本文中的solver.Solver.is_valid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。