
Games::Sudoku::CPSearch - Solve Sudoku problems quickly.

Version 0.14

use Games::Sudoku::CPSearch;
my $puzzle = <<PUZZLE;
4.....8.5
.3.......
...7.....
.2.....6.
....8.4..
....1....
...6.3.7.
5..2.....
1.4......
PUZZLE
$puzzle =~ s/\s//g;
my $sudoku = Games::Sudoku::CPSearch->new($puzzle);
print $sudoku->solve(), "\n";

This module solves a Sudoku puzzle using the same constraint propagation technique/algorithm explained on Peter Norvig's website (http://norvig.com/sudoku.html), and implemented there in Python.

Initializes the sudoku solving framework.
Solves the puzzle. Returns the solution as a flat 81 character string.
Sets the puzzle to be solved. The only parameter is the 81 character string representing the puzzle. The only characters allowed are [0-9\.\-]. Sets the puzzle to be solved. You can then reuse the object:
my $o = Games::Sudoku::CPSearch->new($puzzle);
print $o->solve(), "\n";
$o->set_puzzle($another_puzzle);
print $o->solve(), "\n";
Returns the solution string, or the empty string if there is no solution.

These methods are exposed but are not intended to be used.
Returns a hash with squares as keys and "123456789" as each value.
Returns the object's puzzle as an 81 character string.
Returns an list of sudoku "units": rows, columns, boxes for a given square.
Perform the constraint propagation on the Sudoku grid.
Eliminate digit from the square in the grid.
Assign digit to square in grid. Mutually recursive with eliminate().
Returns array of row values: A-I
Returns array of column values: 1-9
Return list of all the squares in a Sudoku grid: A1, A2, ..., A9, B1, ..., I1, ..., I9
Return list of all the units for a given square.
Return list of all the peers for a given square.
Perform search for a given grid after constraint propagation.
Return "cross product" of 2 arrays.
Returns undef if the sudoku solution is not valid. Returns 1 if it is.

Martin-Louis Bright, <mlbright at gmail.com>

Please report any bugs or feature requests to bug-games-sudoku-cpsearch at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Sudoku-CPSearch. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

You can find documentation for this module with the perldoc command.
perldoc Games::Sudoku::CPSearch
You can also look for information at:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-Sudoku-CPSearch

Peter Norvig, for the explanation/tutorial and python code at http://www.norvig.com/sudoku.html.

Copyright 2008 Martin-Louis Bright, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.