Giter VIP home page Giter VIP logo

programmingmonke / sudokusolver Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 10 KB

Takes an unsolved Sudoku Grid as input, given as a continuous string of 81 characters. Program prints out the final output as a 9x9 grid and uses Constraint Propagation (AC3 Algorithm) and Backtracking Search. In AC3, it checks arc consistency and enforces it by removing values from the domain of unassigned variables.

Python 100.00%
ac3 ai backtracking-algorithm sudoku-solver

sudokusolver's Introduction

Sudoku Solver

Takes an unsolved Sudoku Grid as input, given as a continuous string of 81 characters.

In this Python-written project, the program prints out the final output as a 9x9 grid and uses Constraint Propagation (AC3 Algorithm) and Backtracking Search. In AC3, it checks arc consistency and enforces it by removing values from the domain of unassigned variables. The solver will try to solve it with AC3 alone, but if it fails it will resort to Backtracking Search.

Examples of sample input for the board are given below.

Run Locally

Clone the project (in your git directory)

  git clone [email protected]:ProgrammingMonke/SudokuSolver.git

Go to the project directory

  cd SudokuSolver/

Run the program

  python3 SudokuSolver.py

Example Strings (used below as well)

..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..

...26.7.168..7..9.19...45..82.1...4...46.29...5...3.28..93...74.4..5..367.3.18...

Output

Below is sample output generated by the program.

Example 1

Please enter the unsolved Sudoku Grid string: ..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..

Current Board:

..3|.2.|6..
9..|3.5|..1
..1|8.6|4..
-----------
..8|1.2|9..
7..|...|..8
..6|7.8|2..
-----------
..2|6.9|5..
8..|2.3|..9
..5|.1.|3..

Finished Board w/ AC3:

483|921|657
967|345|821
251|876|493
-----------
548|132|976
729|564|138
136|798|245
-----------
372|689|514
814|253|769
695|417|382

Finished Board w/ Backtracking:

483|921|657
967|345|821
251|876|493
-----------
548|132|976
729|564|138
136|798|245
-----------
372|689|514
814|253|769
695|417|382
...

Example 2

Please enter the unsolved Sudoku Grid string: ..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..

Current Board:

..3|.2.|6..   
9..|3.5|..1   
..1|8.6|4..
-----------
..8|1.2|9..
7..|...|..8
..6|7.8|2..
-----------
..2|6.9|5..
8..|2.3|..9
..5|.1.|3..

Finished Board w/ AC3:

483|921|657
967|345|821
251|876|493
-----------
548|132|976
729|564|138
136|798|245
-----------
372|689|514
814|253|769
695|417|382

Finished Board w/ Backtracking:

483|921|657
251|876|493
-----------
548|132|976
729|564|138
-----------
372|689|514
814|253|769
695|417|382

sudokusolver's People

Contributors

programmingmonke avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.