<back

# Sudoku source

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

You will need these 6 files

*Sudoku.pm* | the perl sudoku solve module |

*SudokuCGI.pm* | the perl sudoku CGI module |

*sudoku.plx* | the perl console test sudoku script |

*solve.cgi* | the (perl) cgi script for the solver |

*generate.cgi* | the (perl) cgi script for the generator |

*sudoku.css* | CSS for the results of the *.cgi |

out of sudoku.tgz (gzipped tar-archive)
The Modules *Sudoku.pm* and *SudokuCGI.pm* should stay in the same directory as *sudoku.plx*,
*solve.cgi* or *generator.cgi* does -
because the actual directory *.* is normaly included in @INC - so both can use Sudoku.

## sudoku.plx

For sudoku.plx you have to create an input-puzzle-file. This file has 9 lines
for each sudoku-puzzle-lines. Each line has 9 characters. A 1,2,3...9 stay for
it self. Any other character stay for *any* which is to solve.

Save the following as puzzle.in

.7.1.8.6.
..1...9..
.6.....2.
3.62.71.4
.........
1.95.42.6
.1.....8.
..7...4..
.3.4.9.5.

Then enter

./sudoku.plx puzzle.in

If you have more puzzles stored in the directories say *easy/* and *hard/* you could say

./sudoku.plx easy/* hard/*

## solve.cgi generate.cgi

Save both together with Sudoku.pm and sudoku.css on your WEB-server and configure your server to call .cgi as cgi-scripts.

## Suduku.pm

The whole puzzle-square is represented with a 81 element array. It is stored row by row. So index 0..8 is the first row, index 9..17 the second, ...

The results are stored as array of references to such 81 element squares.

Use and call the solver as follows:

use Sudoku;
...
my @square;
my $maxres = 15;
#
# fill the square all other than 1..9 says don't care
#
my @results = Sudoku::Solve($maxres, @square);
for my $result ( @results )
{
#
# output @$result
#
}
printf "class = %s [%d]\n", Sudoku::Class, Sudoku::Measure;

<back