一个用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>
相关推荐
倒头就睡的小比特3 天前
算法竞赛C++常用的STL
c++·算法
小羊没烦恼!3 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
猎头南楼3 天前
知识社区推荐系统实践:新用户冷启动与长短期兴趣建模的挑战 资深推荐算法工程师
人工智能·深度学习·算法·机器学习
旖旎夜光3 天前
力控面试题 01.01: 判定字符是否唯一(位运算) —— 题解
c++·学习·算法·leetcode·力控
wzdark3 天前
大规模并行计算中的负载均衡算法研究4
算法
Because_of_Her13 天前
并查集-听课笔记
笔记·算法·并查集
码流子3 天前
高速公路安全监测实践:碰撞监测预警+物联网底座,从感知到处置的闭环
大数据·人工智能·物联网·算法·架构
another heaven3 天前
【算法/C++ MD5算法能否逆解码?原理、C++实现与同类哈希算法对比】
c++·算法·哈希算法
wzdark3 天前
从算法设计模式看编程思维的抽象能力4
算法
2601_962218613 天前
万象生鲜系统称重自动多退少补算法解决生鲜非标品痛点
大数据·数据库·人工智能·python·算法