# -*- coding: utf-8 -*-
def solveSudoku(puzzle):
from sudoku import Sudoku #是的,写这里了
puzzle = Sudoku(3, 3, board=puzzle) #初始化
puzzle.show() #显示
solution = puzzle.solve() #求解
print("求解结果:")
solution.show() #显示
result = solution.board #获取list形式
return result #返回
#==================主程序=====================
puzzle=[[4, 0, 6, 0, 0, 0, 0, 9, 0],
[0, 0, 0, 3, 1, 0, 0, 0, 6],
[1, 0, 8, 0, 0, 7, 0, 0, 0],
[0, 8, 0, 0, 4, 0, 6, 0, 0],
[0, 6, 0, 7, 0, 3, 0, 2, 0],
[0, 0, 7, 0, 9, 0, 0, 8, 0],
[0, 0, 0, 8, 0, 0, 2, 0, 3],
[3, 0, 0, 0, 5, 2, 0, 0, 0],
[0, 4, 0, 0, 0, 0, 5, 0, 7]]
result=solveSudoku(puzzle)
print(result)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.