Richard H.Administrator
(KiX Supporter)
2009-01-02 03:37 PM
Sudoku solver

The attached script is a simple brute-force / backtracking solver for Sudoku puzzles.

It will always find a solution (if there is one), but depending on the grid it may take a very long time.

As it is brute force it does not use a recognisable human technique to solve the grid, so is not useful for learning how to solve puzzles.

A blank starting grid will generate a random completed puzzle - useful if you are interested in creating your own puzzles.

The solving algorithm is based on Emanuele Feronato's PHP code found here with only minor modifications to make it work in KiXtart.

Optimising for KiXtart is a lesson left to the reader...

[edit]
I've just re-read Emanuele's page and he states that the algorithm *is* emulating a human method of solving the grid. It looks more like an optimised brute force solve to me, but then I'm not a people person ;\)
[/edit]


BillBarnard
(Starting to like KiXtart)
2009-01-23 04:37 PM
Re: Sudoku solver

I'm getting this error when I run it. I can't see anything obvious yet.

Starting grid: Pass #353 Time: 294 seconds
+---+---+---+ +---+---+---+
|6..|..5|..7| |624|185|..7|
|9..|7..|..6| |9..|724|..6|
|.1.|.3.|4..| |81.|.3.|4..|
+---+---+---+ +---+---+---+
|...|8..|.1.| |...|8..|.1.|
|2.9|...|..5| |2.9|...|..5|
|.6.|..2|...| |.6.|..2|...|
+---+---+---+ +---+---+---+
|..2|.9.|.5.| |..2|69.|.5.|
|5..|..3|7.1| |5..|..3|7.1|
|1..|4..|..3| |1..|4..|..3|
+---+---+---+ +---+---+---+

ERROR : invalid method/function call: missing comma!
Script: U:\158.KIX
Line : 213

My line 213 is:-

$y=UBound($aPossibilities[$x])

In the Function udfGetCellWithLeastSolutions($aPossibilities)

Anyone else tried it out yet?


Richard H.Administrator
(KiX Supporter)
2009-01-26 10:08 AM
Re: Sudoku solver

Thanks for the bug report.

I'll take a look as soon as I get some free time.