一个用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>
相关推荐
x_yeyue2 小时前
三角形数
笔记·算法·数论·组合数学
念何架构之路3 小时前
Go语言加密算法
数据结构·算法·哈希算法
AI科技星3 小时前
《数学公理体系·第三部·数术几何》(2026 年版)
c语言·开发语言·线性代数·算法·矩阵·量子计算·agi
失去的青春---夕阳下的奔跑3 小时前
560. 和为 K 的子数组
数据结构·算法·leetcode
黎阳之光4 小时前
黎阳之光:以视频孪生重构智慧医院信息化,打造高标项目核心竞争力
大数据·人工智能·物联网·算法·数字孪生
丷丩4 小时前
三级缓存下MVT地图瓦片服务性能优化策略
算法·缓存·性能优化·gis·geoai-up
m0_629494734 小时前
LeetCode 热题 100-----25.回文链表
数据结构·算法·leetcode·链表
ʚ希希ɞ ྀ5 小时前
单词拆分----dp
算法
智者知已应修善业6 小时前
【51单片机LED闪烁10次数码管显示0-9】2023-12-14
c++·经验分享·笔记·算法·51单片机
智者知已应修善业6 小时前
【51单片机2按键控制1个敞亮LED灯闪烁和熄灭】2023-11-3
c++·经验分享·笔记·算法·51单片机