# Pattern Based Sudoku Solving Algorithms (part Β)

I wonder if I ever get serious and finish my projects or any for that matter. Last time I presented a fairly complicated algorithm idea about a more humanized based Sudoku solver instead of the brute force ones that applications usually utilize.

Someone can argue, what’s the point of creating a fairly complicated solution to a simple problem that can be solved in just a few seconds using brute force.

Well Because its fun. So, here you go, another made up Sudoku solving algorithm

This time, I though, that it would be interesting to combine my geometrical and topological background, as well as some GIS based algorithms that we have developed over time.

The first implementation cannot solve all Sudoku puzzles but it can do fairly well in medium strength ones like this one

input

output

The first step in solving is pretty straight forward. Create a set of horizontal and vertical lines through each number and Classifying two types of intersections (green and yellow, see image below).

It is pretty much obvious, on the above diagram, that where the arrow points the number 8 should be filled.
The same algorithm can be applied three-wise horizontally, vertically and as the examples box-based.

The core algorithm lies in the following code
where _lnsGeometrys[i] is the collection of available horizontal lines,
_clsGeometrys[i] is the collection of available vertical lines
and _binaryMatrix is a sudoku matrix filled with zeros

STEP A) The algorithm chooses the lines that are needed

STEP B) Then it calculated all intersections

STEP C) creates a binary matrix with all intersections points

STEP D) each number with its equivalent binary matrix is fed in the solver function (see STEP A, function)

Obviously every time a number is filled, the process repeats it self until it either solves the puzzle or reach a dead end.