Skip to main content

A Python Sudoku solver and generator

Project description

Sudoku-py

Overview

Sudoku-py allows you to represent Sudoku boards easily. While also giving you the ability to solve and generate your own Sudoku boards.

Examples

Generator Example

from sudoku_py import SudokuGenerator

sudokuGenerator = SudokuGenerator(board_size=9)

sudokuGenerator.generate(cells_to_remove=50, symmetry_removal=True)

print(sudokuGenerator)
0 0 0 | h 0 0 | d e 0 
e 0 0 | 0 0 0 | 0 0 h 
0 h 0 | b 0 0 | 0 0 0 
---------------------
d b a | g h 0 | 0 0 e 
0 e i | a 0 f | g d 0 
c 0 0 | 0 b d | h a i 
---------------------
0 0 0 | 0 0 b | 0 h 0 
f 0 0 | 0 0 0 | 0 0 c 
0 d h | 0 0 g | 0 0 0 

sudokuGenerator.board_exchange_values({'a': 9, 'b': 8, 'c': 7, 'd': 6, 'e': 5, 'f': 4, 'g': 3, 'h': 2, 'i': 1})

print(sudokuGenerator)
0 0 0 | 2 0 0 | 6 5 0 
5 0 0 | 0 0 0 | 0 0 2 
0 2 0 | 8 0 0 | 0 0 0 
---------------------
6 8 9 | 3 2 0 | 0 0 5 
0 5 1 | 9 0 4 | 3 6 0 
7 0 0 | 0 8 6 | 2 9 1 
---------------------
0 0 0 | 0 0 8 | 0 2 0 
4 0 0 | 0 0 0 | 0 0 7 
0 6 2 | 0 0 3 | 0 0 0 

Sudoku Board

from sudoku_py import Sudoku
Sudoku(board=[
    [0,0,0,2,0,0,6,5,0],
    [5,0,0,0,0,0,0,0,2],
    [0,2,0,8,0,0,0,0,0],
    [6,8,9,3,2,0,0,0,5],
    [0,5,1,9,0,4,3,6,0],
    [7,0,0,0,8,6,2,9,1],
    [0,0,0,0,0,8,0,2,0],
    [4,0,0,0,0,0,0,0,7],
    [0,6,2,0,0,3,0,0,0]
])

print(sudoku)
0 0 0 | 2 0 0 | 6 5 0 
5 0 0 | 0 0 0 | 0 0 2 
0 2 0 | 8 0 0 | 0 0 0 
---------------------
6 8 9 | 3 2 0 | 0 0 5 
0 5 1 | 9 0 4 | 3 6 0 
7 0 0 | 0 8 6 | 2 9 1 
---------------------
0 0 0 | 0 0 8 | 0 2 0 
4 0 0 | 0 0 0 | 0 0 7 
0 6 2 | 0 0 3 | 0 0 0 

sudoku.solve(solutions=1)

print(sudoku)
1 3 8 | 2 4 7 | 6 5 9 
5 7 4 | 6 3 9 | 1 8 2 
9 2 6 | 8 1 5 | 4 7 3 
---------------------
6 8 9 | 3 2 1 | 7 4 5 
2 5 1 | 9 7 4 | 3 6 8 
7 4 3 | 5 8 6 | 2 9 1 
---------------------
3 1 7 | 4 5 8 | 9 2 6 
4 9 5 | 1 6 2 | 8 3 7 
8 6 2 | 7 9 3 | 5 1 4 

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_py-1.0.0.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

sudoku_py-1.0.0-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

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