Games-Sudoku-PatternSolver

 view release on metacpan or  search on metacpan

lib/Games/Sudoku/PatternSolver.pod  view on Meta::CPAN

=encoding UTF-8

=head1 NAME

Games::Sudoku::PatternSolver - Solve and generate Sudoku 9x9 puzzles.

=head1 DESCRIPTION

A Sudoku solver and generator. It works by application of the pattern overlay method (POM) in a backtracking process.

B<Note:> I<For this module the term 'pattern' refers to a 9x9 matrix, holding the final 9 positions of any single symbol.>

=head1 SYNOPSIS

  use Games::Sudoku::PatternSolver qw( solve );

  $result = solve( '.2.4.6.8....2......9......1..4......51.....9.....4.5.335..6....9...823.5..1.....8' );
  print_grid( $result->{solutions}[0] );

  use Games::Sudoku::PatternSolver::Generator qw(get_grid_builder get_sudoku_builder);

  $grid_builder = get_grid_builder();
  $solution = &$grid_builder( $do_shuffle );

  $generator = get_sudoku_builder( $solution );
  $sudokuHash = &$generator();
  print $sudokuHash->{strPuzzle}, "\n";

=head1 MODULES AND UTILITIES

=head2 PatternSolver

Can solve any valid standard 9x9 puzzle.

It is notable in that it tries to find a combination of 9 out of 46656 unique patterns in which a number may be placed on the grid. 
If a faulty puzzle has very many solutions and the $MAX_SOLUTIONS switch is false, the solver can find them all, 
given sufficient time and computer memory.

=head3 solve( <puzzle> )

The input can be an 81-character string with zeroes or non-digits for empty cells, it can be 81 individual values, an arrayref with these or a 9x9 AoA.

The return value is an unblessed hash reference, populated with properties of the puzzle and the results of the solving process:

=over 3

=item strPuzzle

=item givensCount

=item uniqueGivens

Describing the puzzle.

=item seconds

Time needed for the entire solving process.

=item solutionCount

Normally == '1'. Is subject to $MAX_SOLUTIONS and the nature of the puzzle.

=item solutions

An arrayref with string representation of the one or more solutions.

=item logicSolved

Boolean, telling whether the limited power from L<PatternSolver::CPLogic|/"PatternSolver::CPLogic"> sufficed for completion.



( run in 2.120 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )