Games::Sudoku::CPSearch - Solve Sudoku problems quickly.
Version 1.00
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 open FH, ">example.txt"; print FH $puzzle; close FH; my $sudoku = Games::Sudoku::CPSearch->new("example.txt"); 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->set_puzzle($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>
<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.
bug-games-sudoku-cpsearch at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Games::Sudoku::CPSearch
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-Sudoku-CPSearch
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Games-Sudoku-CPSearch
CPAN Ratings
http://cpanratings.perl.org/d/Games-Sudoku-CPSearch
Search CPAN
http://search.cpan.org/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.
To install Games::Sudoku::CPSearch, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Games::Sudoku::CPSearch
CPAN shell
perl -MCPAN -e shell install Games::Sudoku::CPSearch
For more information on module installation, please visit the detailed CPAN module installation guide.