Skip to main content

Sudoku solver

Project description

sudoku

Developer Guide

If you are new to using nbdev here are some useful pointers to get you started.

Install sudoku in Development mode

# make sure sudoku package is installed in development mode
$ pip install -e .

# make changes under nbs/ directory
# ...

# compile to have changes apply to sudoku
$ nbdev_prepare

Usage

Installation

Install latest from the GitHub repository:

$ pip install git+https://github.com/emagri/sudoku.git

or from conda

$ conda install -c emagri sudoku

or from pypi

$ pip install sudoku

Documentation

Documentation can be found hosted on this GitHub repository’s pages. Additionally you can find package manager specific guidelines on conda and pypi respectively.

How to use

Instantiate a sudoku.board.Board class, passing it a list of 9 rows containing the initial Sudoku puzzle.

board = ['8-----41-', 
         '-6-9-----', 
         '3-2------', 
         '-5---814-', 
         '4----1--3', 
         '-8---326-', 
         '1-9------', 
         '-7-3-----', 
         '2-----85-']

Invoking its method solve, you can get a log of the processing and the final result.

b = Board(board)
b.solve(False)
 |0-----------|1-----------|2-----------|3-----------|4-----------|5-----------|6-----------|7-----------|8-----------|
0| 8          | 9          | 5          |   -2---6---| 3          | 7          | 4          | 1          |   -2---6---|
1| 7          | 6          | 4          | 9          | 1          |   -2--5----|   --3-5----|   -23------| 8          |
2| 3          | 1          | 2          |   ---456-8-|   ---456-8-|   ---456---|   ----567-9|   ------7-9|   ----5---9|
3| 6          | 5          | 3          |   -2----7--|   -2------9| 8          | 1          | 4          |   ------7-9|
4| 4          | 2          | 7          |   ----56---|   ----56--9| 1          |   ----5---9| 8          | 3          |
5| 9          | 8          | 1          |   ---45-7--|   ---45----| 3          | 2          | 6          |   ----5-7--|
6| 1          | 4          | 9          |   -2--56-8-|   -2--56-8-|   -2--56---|   --3---7--|   --3---7--|   -2---6---|
7| 5          | 7          | 8          | 3          |   -2-4-6---|   -2-4-6---|   -----6--9|   -2------9| 1          |
8| 2          | 3          | 6          | 1          | 7          | 9          | 8          | 5          | 4          |
 |0-----------|1-----------|2-----------|3-----------|4-----------|5-----------|6-----------|7-----------|8-----------|

<Solution.NOT_FOUND: 'solution not found'>

The parameter use_brute_force (disabled by default) enables the use of brute force in case attemps based on logic are not enough to solve the puzzle.

b = Board(board)
b.solve(True)
 |0--|1--|2--|3--|4--|5--|6--|7--|8--|
0| 8 | 9 | 5 | 2 | 3 | 7 | 4 | 1 | 6 |
1| 7 | 6 | 4 | 9 | 1 | 5 | 3 | 2 | 8 |
2| 3 | 1 | 2 | 8 | 6 | 4 | 9 | 7 | 5 |
3| 6 | 5 | 3 | 7 | 2 | 8 | 1 | 4 | 9 |
4| 4 | 2 | 7 | 6 | 9 | 1 | 5 | 8 | 3 |
5| 9 | 8 | 1 | 4 | 5 | 3 | 2 | 6 | 7 |
6| 1 | 4 | 9 | 5 | 8 | 6 | 7 | 3 | 2 |
7| 5 | 7 | 8 | 3 | 4 | 2 | 6 | 9 | 1 |
8| 2 | 3 | 6 | 1 | 7 | 9 | 8 | 5 | 4 |
 |0--|1--|2--|3--|4--|5--|6--|7--|8--|

<Solution.ONE_SOLUTION: 'found a solution'>

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

sudoku_board_solver_em-0.0.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

sudoku_board_solver_em-0.0.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file sudoku_board_solver_em-0.0.1.tar.gz.

File metadata

  • Download URL: sudoku_board_solver_em-0.0.1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for sudoku_board_solver_em-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c77fab1fc47d03955b038f97bf52016a55090ad04401780519aba1301f0dbfb3
MD5 829f727199e34d45e126a37537517309
BLAKE2b-256 2559188629d6a81f50222f8739fb25f86b0d4e7dd1636ef95881c6ecfe7991f2

See more details on using hashes here.

File details

Details for the file sudoku_board_solver_em-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sudoku_board_solver_em-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7aedc100dc7df0fff10ee65ddb592f984008e52c22688f491a032e4655862af9
MD5 47f4c7e189f08162440c07acb920060f
BLAKE2b-256 23a4af37bbaa402cfaca5849569eb8e3df41aa7255cd17b81712cca0c4fffefc

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