Skip to content

Solves sudoku puzzles with large grids (up to 512x512).

Notifications You must be signed in to change notification settings

sigh/Large-Sudoku-Solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Large Sudoku Solver

A solver for large sudoku grids (up to 512x512). Also solves Sudoku-X puzzles.

Running

Requires rust to compile and run:

cargo run --release solve <input_filename>

Algorithm

The solver works by representing the puzzles as a set of all-different constraints, then enforcing generalized arc consistency on each constraint.

Generalized arc consistency is enforced efficiently as described in (Régin, 1994):

  1. Represent the constraint as a bipirate graph between cells and values, then find a maximal matching using the Ford-Fulkerson algorithm.
  2. Convert the bipirate graph into a directed graph by making each edge from a cell to a value a forward edge, then reversing those edges in the maximal matching found.
  3. Find and eliminate edges in the strongly-connected components of the directed graph using Tarjan's algorithm.

This is equivalent to resolving all naked and hidden singles/pairs/triples/etc in a single pass.

Furthermore, the following optimizations are also implemented:

  • Store the maximal matching found between each invocation for each constraint. This allows us to only have to re-run the matching algorithm on the cells where the matching no longer applies. In the common case, this let's us skip step (1) altogether.
  • Adds redundant same-value constraints for intersecting regions. This is equivalent to the pointing pairs/triples technique.

Other than that it is a backtracking solver which uses an approximation of the dom/wdeg heuristic to choose the cell order. The solver state consists of a vector of bitsets representing the valid values each cell can take. The algorithms above are implemented efficiently against the bitset representation.

About

Solves sudoku puzzles with large grids (up to 512x512).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages