This project was developed under the Logic For Programming course of the Bachelors Degree in Computer Science and Engineering, at Instituto Superior Técnico, Lisbon.
We developed a sudoku solver using SWI-Prolog.
- If you don't have SWI-Prolog:
If you are running on MacOS and you have MacPorts or homebrew, just go here.
Otherwise, you can download it here!
-
Download the project here! and unzip at a desired directory.
-
To run the project:
On Mac, go to the root folder of the project on terminal and run:
swipl -l projeto.pl
On Windows:
Double-click the projeto.pl
file to load it in the explorer. This will start SWI-Prolog. More info here.
- To solve a sudoku, give as input any unsolved sudoku as a list of list. For example, below you can see how you solve the puzzle P:
?- P = [[[ ],[3],[ ],[ ],[ ],[1],[ ],[ ],[ ]],
[[ ],[ ],[6],[ ],[ ],[ ],[ ],[5],[ ]],
[[5],[ ],[ ],[ ],[ ],[ ],[9],[8],[3]],
[[ ],[8],[ ],[ ],[ ],[6],[3],[ ],[2]],
[[ ],[ ],[ ],[ ],[5],[ ],[ ],[ ],[ ]],
[[9],[ ],[3],[8],[ ],[ ],[ ],[6],[ ]],
[[7],[1],[4],[ ],[ ],[ ],[ ],[ ],[9]],
[[ ],[2],[ ],[ ],[ ],[ ],[8],[ ],[ ]],
[[ ],[ ],[ ],[4],[ ],[ ],[ ],[3],[ ]]], resolve(P, Sol), write_puzzle(Sol).
The output should be:
[[8],[3],[2],[5],[9],[1],[6],[7],[4]]
[[4],[9],[6],[3],[8],[7],[2],[5],[1]]
[[5],[7],[1],[2],[6],[4],[9],[8],[3]]
[[1],[8],[5],[7],[4],[6],[3],[9],[2]]
[[2],[6],[7],[9],[5],[3],[4],[1],[8]]
[[9],[4],[3],[8],[1],[2],[7],[6],[5]]
[[7],[1],[4],[6],[3],[8],[5],[2],[9]]
[[3],[2],[9],[1],[7],[5],[8],[4],[6]]
[[6],[5],[8],[4],[2],[9],[1],[3],[7]]
P = [[[], [3], [], [], [], [1], [], []|...], [[], [], [6], [], [], [], []|...], [[5], [], [], [], [], []|...], [[], [8], [], [], []|...], [[], [], [], []|...], [[9], [], [...]|...], [[7], [...]|...], [[]|...], [...|...]],
Sol = [[[8], [3], [2], [5], [9], [1], [6], [...]|...], [[4], [9], [6], [3], [8], [7], [...]|...], [[5], [7], [1], [2], [6], [...]|...], [[1], [8], [5], [7], [...]|...], [[2], [6], [7], [...]|...], [[9], [4], [...]|...], [[7], [...]|...], [[...]|...], [...|...]] .
A few resources to get you started if this is your first SWI-Prolog project:
For help getting started with SWI-Prolog,check online documentation. On their website, you can also find tutorials and more useful information!
