一个用AC-3算法求解数独的程序

github存储库

将python代码复制到同一个目录,比如C:\d\ac3, 然后用如下命令行运行

复制代码
C:\d\ac3>python driver.py
Would you like to use a preloaded Sudoku board?: (y/n)y
Choose one of the following levels:
[1] No Solution
[2] Easy
[3] Medium
[4] Hard
[5] Hardest in the World
Please input the level of difficulty: 1

8 - - |- - - |- - -
- - 3 |6 - - |- - -
- 7 - |- 9 - |2 - -
-------------------
- 5 - |- - 7 |- - -
- - - |- 4 5 |7 - -
- - - |1 - - |- 3 -
-------------------
- - 1 |- - - |- 6 8
- - 8 |5 - - |- 1 -
- 9 9 |9 9 9 |9 9 9

Error: There is no solution to this sudoku puzzle


C:\d\ac3>python driver.py
Would you like to use a preloaded Sudoku board?: (y/n)y
Choose one of the following levels:
[1] No Solution
[2] Easy
[3] Medium
[4] Hard
[5] Hardest in the World
Please input the level of difficulty: 5

8 - - |- - - |- - -
- - 3 |6 - - |- - -
- 7 - |- 9 - |2 - -
-------------------
- 5 - |- - 7 |- - -
- - - |- 4 5 |7 - -
- - - |1 - - |- 3 -
-------------------
- - 1 |- - - |- 6 8
- - 8 |5 - - |- 1 -
- 9 - |- - - |4 - -


8 1 2 |7 5 3 |6 4 9
9 4 3 |6 8 2 |1 7 5
6 7 5 |4 9 1 |2 8 3
-------------------
1 5 4 |2 3 7 |8 9 6
3 6 9 |8 4 5 |7 2 1
2 8 7 |1 6 9 |5 3 4
-------------------
5 2 1 |9 7 4 |3 6 8
4 3 8 |5 2 6 |9 1 7
7 9 6 |3 1 8 |4 5 2

Solve Time: 0.7645819187164307 seconds

C:\d\ac3>python driver.py
Would you like to use a preloaded Sudoku board?: (y/n)y
Choose one of the following levels:
[1] No Solution
[2] Easy
[3] Medium
[4] Hard
[5] Hardest in the World
Please input the level of difficulty: 4

- 7 - |- 4 2 |- - -
- - - |- - 8 |6 1 -
3 9 - |- - - |- - 7
-------------------
- - - |- - 4 |- - 9
- - 3 |- - - |7 - -
5 - - |1 - - |- - -
-------------------
8 - - |- - - |- 7 6
- 5 4 |8 - - |- - -
- - - |6 1 - |- 5 -


1 7 6 |3 4 2 |9 8 5
4 2 5 |9 7 8 |6 1 3
3 9 8 |5 6 1 |4 2 7
-------------------
2 6 1 |7 8 4 |5 3 9
9 8 3 |2 5 6 |7 4 1
5 4 7 |1 9 3 |2 6 8
-------------------
8 1 9 |4 2 5 |3 7 6
6 5 4 |8 3 7 |1 9 2
7 3 2 |6 1 9 |8 5 4

Solve Time: 0.1383507251739502 seconds

C:\d\ac3>python driver.py
Would you like to use a preloaded Sudoku board?: (y/n)y
Choose one of the following levels:
[1] No Solution
[2] Easy
[3] Medium
[4] Hard
[5] Hardest in the World
Please input the level of difficulty: 3

- - - |5 4 - |- - 8
6 - - |- - 2 |3 - -
- - 7 |- - 3 |- 9 -
-------------------
- 3 1 |- 5 - |- 2 -
- - - |- - - |- - -
- 4 - |- 3 - |7 1 -
-------------------
- 9 - |7 - - |2 - -
- - 8 |6 - - |- - 5
1 - - |- 2 4 |- - -


2 1 3 |5 4 9 |6 7 8
6 8 9 |1 7 2 |3 5 4
4 5 7 |8 6 3 |1 9 2
-------------------
9 3 1 |4 5 7 |8 2 6
8 7 2 |9 1 6 |5 4 3
5 4 6 |2 3 8 |7 1 9
-------------------
3 9 4 |7 8 5 |2 6 1
7 2 8 |6 9 1 |4 3 5
1 6 5 |3 2 4 |9 8 7

Solve Time: 0.02900862693786621 seconds

C:\d\ac3>
相关推荐
TracyCoder12312 小时前
LeetCode Hot100(15/100)——54. 螺旋矩阵
算法·leetcode·矩阵
u01092727113 小时前
C++中的策略模式变体
开发语言·c++·算法
2501_9418372614 小时前
停车场车辆检测与识别系统-YOLOv26算法改进与应用分析
算法·yolo
六义义15 小时前
java基础十二
java·数据结构·算法
四维碎片15 小时前
QSettings + INI 笔记
笔记·qt·算法
Tansmjs15 小时前
C++与GPU计算(CUDA)
开发语言·c++·算法
独自破碎E16 小时前
【优先级队列】主持人调度(二)
算法
weixin_4454766816 小时前
leetCode每日一题——边反转的最小成本
算法·leetcode·职场和发展
打工的小王16 小时前
LeetCode Hot100(一)二分查找
算法·leetcode·职场和发展
Swift社区16 小时前
LeetCode 385 迷你语法分析器
算法·leetcode·职场和发展