Thanks to visit codestin.com
Credit goes to github.com

Skip to content

r-spiewak/sudoku_solver

Repository files navigation

Sudoku Solver

Sudoku Solver repo. Useful for solving Sudoku puzzles.

Installation

  1. (If poetry is not already installed:) curl -sSL https://install.python-poetry.org | python3 -
  2. git clone https://github.com/r-spiewak/sudoku_solver.git
  3. poetry install

Usage

To solve a sudoku puzzle, first create the puzzle as a valid JSON object (either as a string or in a .json file - see example in tests/test_objects/test_puzzle.json), with the integer 0 as the placeholder for any unknown element.

Then, run the script:

poetry run --puzzle tests/test_objects/test_puzzle.json

Sample output for solvable puzzle:

Puzzle: [[5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 0, 0, 0, 8, 0, 0, 7, 9]]
Solved puzzle: [[5, 3, 4, 6, 7, 8, 9, 1, 2], [6, 7, 2, 1, 9, 5, 3, 4, 8], [1, 9, 8, 3, 4, 2, 5, 6, 7], [8, 5, 9, 7, 6, 1, 4, 2, 3], [4, 2, 6, 8, 5, 3, 7, 9, 1], [7, 1, 3, 9, 2, 4, 8, 5, 6], [9, 6, 1, 5, 3, 7, 2, 8, 4], [2, 8, 7, 4, 1, 9, 6, 3, 5], [3, 4, 5, 2, 8, 6, 1, 7, 9]]

Sample output for unsolvable puzzle:

Puzzle: [[5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 0, 0, 0, 8, 0, 8, 7, 9]]
No solution exists.

Dev Installation

After completing the regular installation above, also do the following:

  1. poetry run pre-commit install

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published