本文整理汇总了Python中Solver.initial_fill方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.initial_fill方法的具体用法?Python Solver.initial_fill怎么用?Python Solver.initial_fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solver
的用法示例。
在下文中一共展示了Solver.initial_fill方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reduce_sudoku
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import initial_fill [as 别名]
def reduce_sudoku(s, difficulty):
elements = list(range(81))
random.shuffle(elements)
while elements:
row = elements[0] // 9
col = elements[0] % 9
temp = s[row][col]
s[row][col] = 0
elements = elements[1:]
copy_s = [
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
]
for i in range(9):
for j in range(9):
copy_s[i][j] = s[i][j]
Solver.initial_fill(copy_s)
for line in copy_s:
if 0 in line:
num_solutions = number_solutions(copy_s, 0, 0)
if num_solutions > 1:
s[row][col] = temp
if difficulty == 1:
return
if difficulty == 2 and len(elements) <= 40:
return
if difficulty == 3 and len(elements) <= 24:
return
break
return
示例2: post
# 需要导入模块: import Solver [as 别名]
# 或者: from Solver import initial_fill [as 别名]
def post(self):
guestbook_name = self.request.get('guestbook_name',
DEFAULT_GUESTBOOK_NAME)
greetings_query = Greeting.query(
ancestor=guestbook_key(guestbook_name)).order(-Greeting.date)
greetings = greetings_query.fetch(1)
s = [[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0]]
for i in range(0,81):
row = i // 9
col = i % 9
if sent_cells[i] != '':
s[row][col] = int(sent_cells[i])
else:
s[row][col] = 0
for greeting in greetings:
for i in range(0,81):
if sent_cells[i] == '0':
sent_cells[i] = str(self.request.get('e'+str(i/9)+str(i%9)))
"""fname = 'Solutions.txt'
with open(fname) as f:
content = f.readlines()
content = [x.strip('\n') for x in content]
s = content[greeting.sudoku_id]"""
Solver.initial_fill(s)
for line in s:
if 0 in line:
Solver.solve(s, 0, 0)
break
for i in range(0,9):
for j in range(0,9):
sol_cells[9*i+j] = str(s[i][j])
flag = True
for i in range(0,81):
if sol_cells[i] != sent_cells[i]:
flag = False
break
template_values = {
'flag': flag,
'sol_cells': sol_cells,
}
template = JINJA_ENVIRONMENT.get_template('result.html')
self.response.write(template.render(template_values))