o
odin.langpkg.dev
packages / library / odindoku

odindoku

34ce803library

Sudoku solving in Odin!

No license · updated 3 years ago

Sudoku solving in Odin

This is a repo to store a pair of sudoku solving projects in Odin. Both use a depth first search algorithm for solving, and prioritise cells with fewer possibilities, but they differ in how they find those cells in the grid.

First try

The first uses a simple linear search, and was easy to implement, but is very inefficient, as many cells are needlessly checked to see if they are the minimum.

More optimal

My second approach utilises a dway heap as a priority queue to find the cell with the minimum number of options at each stage of the recursive algorithm. By benchmarking I found that for this application the optimal branch factor was 4, with other branch factors being only slightly worse.

Comparison

When the two resulting programs are timed against one-another using the 50 sudoku puzzles here, heapdoku is around 4 times faster, and when solving an example deigned to be hard for depth first search the difference is even more pronounced, with the heap-based algorithm running at least 10 times faster.