Skip to main content

A Python package for solving Sudoku puzzles.

Project description

SudokuAPI

A Python package for solving Sudoku puzzles.

GitHub code size in bytes PyPI - Downloads PyPI - License PyPI PyPI - Python Version PyPI - Wheel

Installation

$ pip install sudokuapi

Using SudokuAPI

Start by importing the Sudoku class into your Python file.

from sudokuapi import Sudoku

Then, create a 2D list to represent your sudoku puzzle, and use it to construct a new instance of the Sudoku class.

# Can be any valid sudoku puzzle
# Use zero to indicate an empty cell
grid = [
    [5,3,0,0,7,0,0,0,0],
    [6,0,0,1,0,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,0,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]
]

sudoku = Sudoku(grid)

To solve the sudoku, simply class the solve method on the Sudoku object.

sudoku.solve()

You can then use the Sudoku.grid property to access the solved Sudoku, or print it using the print_grid method.

solution = sudoku.grid
sudoku.print_grid()

The output of print_grid looks like this.

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

The Sudoku class attempts to validate your sudoku using the validate_sudoku method. It checks that your sudoku has 9 rows and 9 columns, each containing only digits between 0 and 9. If your sudoku fails validation, Sudoku will print an error to the console.

Invalid Sudoku Grid: [...]

Then, Sudoku will set grid to [], which will escape the solve method if it is called.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sudokuapi-1.1.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sudokuapi-1.1.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file sudokuapi-1.1.0.tar.gz.

File metadata

  • Download URL: sudokuapi-1.1.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for sudokuapi-1.1.0.tar.gz
Algorithm Hash digest
SHA256 8747e06160a5240a1fefe121c426b47c1492d85a48983c20d76a194dd3391405
MD5 8ec82b8eac380033bd07b035c4fc543f
BLAKE2b-256 6fc67cb1492deced8a3d3615db572133f3db20ae0d9bff82a4017c92828ff8fd

See more details on using hashes here.

File details

Details for the file sudokuapi-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: sudokuapi-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for sudokuapi-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfec01721fc4cf6fd58bea9252690aee9bf38f67c19c10403e14929efc9f6ec6
MD5 c8424179cdbcf815814f30be3acc90f5
BLAKE2b-256 b845a4fd2e174696e580c2ce33c4b9da93c570f174698e0fa911c6bc3089b577

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page