Skip to content

Algorithms for solving and generating sudoku puzzles.

Notifications You must be signed in to change notification settings

johnstonematt/sudokus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sudokus

A Python repo for solving and generating Sudoku puzzles, inspired by the following LeetCode problem.

In general, I am prioritising logical conciseness over pure performance (i.e., runtime, memory usage, etc.), but within reason of course.

Solving Techniques

The Sudoku class employs two solving techniques:

  • A purely "deterministic" technique in which a number is only entered if the program is 100% certain that it is correct.
  • A guessing technique which involves making a guess and trying to solve from there (reverting on the guess if the puzzle turns out to be unsolvable).

When generating sudoku puzzles (such as the unfinished puzzle one might find in a newspaper), the goal is to generate a puzzle of sufficient difficulty which can be solved deterministically.

Input Format

The program reads (and generates) a Sudoku as a row-by-row array of integers, where 0 represents and empty space.

sudoku_puzzle = [
    [5, 3, 0, 0, 7, 0, 0, 0, 0],
    [6, 0, 0, 1, 9, 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, 8, 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]
]

About

Algorithms for solving and generating sudoku puzzles.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages