Skip to content

marianasrv/sudoku-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Sudoku Solver 🧩

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.

Table of content

  1. 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!

  1. Download the project here! and unzip at a desired directory.

  2. 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.

  1. 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], [...]|...], [[...]|...], [...|...]] .
This project is powered by SWI-Prolog.

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!

⭐ Star me on GitHub — it helps!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages