Skip to main content

Tools for generating solutions and starting grids for Sudoku.

Project description

sudokulib is a collection of tools that are useful for generating solutions to Sudoku puzzles. It uses a recursive backtracking algorithm (originally written by Jeremy Brown, Cel Destept), and is capable of generating a 3x3 Sudoku in ~0.015 seconds. It can also generate 4x4 Sudokus in ~0.100 seconds (sometimes longer).

Some 5x5 grids have been generated in a matter of seconds using this library, but I’ve also seen the program run for hours without successfully generating a 5x5. Anything beyond 5x5 always seems to take a long time.

You can solve Sudoku puzzles using this library by calling the init_grid method of an instance of Sudoku. This method takes two types of values. Where n is the grid size:

  • a 1-dimensional list with n^4 values

  • a multi-dimensional list with n^2 lists with n^2 values each. Each list represents a row in the grid

The values in the list(s) provided to init_grid must be numeric and greater than 0 but less than n^2 in order to appear in the starting grid. Any other values will be ignored, and the puzzle will be solved with no consideration for such values.

The library also provides utilities for generating starting grids, so you can play Sudoku instead of just generating solutions. There are several difficulty levels to choose from.

Also included in the distribution is a sample class for generating “jigsaw” variations of Sudoku. This class will occasionally generate solvable grids within a second or two, but it takes much longer more often than not.

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

sudokulib-0.6a.tar.gz (40.0 kB view details)

Uploaded Source

File details

Details for the file sudokulib-0.6a.tar.gz.

File metadata

  • Download URL: sudokulib-0.6a.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sudokulib-0.6a.tar.gz
Algorithm Hash digest
SHA256 d2b9910bb23348b5b7a6a473b7e2f8a1ed968b082378cf21594de003f1c8bed5
MD5 53a72a99502a3d4eabf11ac722b05241
BLAKE2b-256 99386a3d57f74a6e633665bbcfdcdf4d7d41cced009be53542074a8b10aaf512

See more details on using hashes here.

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