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 pypi
$ pip install sudoku-board-solver-em
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
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'>
In the above output, the puzzle was only solved partially. In non solved
cells, on the right are showed the candidate values. 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'>
Look at 02_main for other examples and tests.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sudoku_board_solver_em-0.0.2.tar.gz.
File metadata
- Download URL: sudoku_board_solver_em-0.0.2.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
205d082e1cdd8f2e535018568e02087132924d15e13872e972a05b1a25d2cba1
|
|
| MD5 |
422685641e50d56eba412d18269ba30c
|
|
| BLAKE2b-256 |
5cbec6b2d72b26f6145b21e816eb4f208c0cdf3679d275a5628ca4868e260b21
|
File details
Details for the file sudoku_board_solver_em-0.0.2-py3-none-any.whl.
File metadata
- Download URL: sudoku_board_solver_em-0.0.2-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86eacc76b094929eed65f3870b70fc3eb3ff48034d6b3c525963d50d23f9a239
|
|
| MD5 |
4620ad3c4d83e9c405a2556278c971b0
|
|
| BLAKE2b-256 |
4271c427ba453de1dd726f9c7af2628ab5cb0d6dfdfb93f2939ab67254a1abc5
|