Skip to content

A simple and fast implementation of backtrack solving of Sudokus

Notifications You must be signed in to change notification settings

jmdha/sudokubrute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sudokubrute

A simple and fast implementation of backtrack solving of Sudokus

Instructions

The executable runs the solver on the hardest problem found so far. Which takes around 10s to solve.

cargo run -r

Tests checks whether it correctly solves a bunch of different sudokus.

cargo test

Benchmarks test how quickly a few sudokus are solved

cargo bench

Technical details

This is a backtracking solver, see here for explanation on that part.

The most notable part is this code, found here:

pub fn candidates(&self, x: usize, y: usize) -> usize {
  self.valid_ranks[y] & self.valid_files[x] & self.get_box(x, y)
}

This gives for any square the valid values that can be placed there. It does so by finding the intersection between the valid values for rank, file, and the box.

Benchmark

Benchmarked on a AMD Ryzen 5 5600X 6-Core Processor × 6 with Criterion

The benchmarks can be seen here

image

Solves most Sudokus in a few micro seonds and does around 159 million state modifications each second.

About

A simple and fast implementation of backtrack solving of Sudokus

Topics

Resources

Stars

Watchers

Forks

Languages