Games::Sudoku::Solver

Solve 9x9-Sudokus recursively
Download

Games::Sudoku::Solver Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • Fritz Mehner
  • Publisher web site:
  • http://search.cpan.org/~mehner/

Games::Sudoku::Solver Tags


Games::Sudoku::Solver Description

Solve 9x9-Sudokus recursively Games::Sudoku::Solver is a Perl module that solves 9x9-Sudoku puzzles by recursion. There is no restriction to the difficulty and the number of solutions.The puzzle can be stored in a single dimension array or in a file, where unknown cells are presented by zeros or points.SYNOPSIS use Games::Sudoku::Solver qw(:Minimal set_solution_max count_occupied_cells); # specify a Sudoku as flat array (this one has 10 solutions) my @sudoku_raw = qw( 0 4 0 0 2 0 9 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 6 8 5 0 5 8 2 3 0 0 7 0 0 0 0 0 8 0 7 0 0 0 0 0 9 0 0 5 1 3 8 0 9 7 1 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 4 0 3 0 0 0 0 ); my @sudoku; # the Sudoku data structure my @solution; # the solution data structure sudoku_set( \@sudoku, \@sudoku_raw ); # convert raw to internal representation print "\n===== Sudoku =====\n"; sudoku_print( \@sudoku ); # print the Sudoku my $cells_occupied = count_occupied_cells( \@sudoku ); # some statistics print "\n", $cells_occupied, " cells occupied, ", 81-$cells_occupied, " cells free\n"; set_solution_max(4); # stop having 4 solutions found my $solutions = sudoku_solve( \@sudoku, \@solution); # solve the Sudoku foreach my $n ( 1..$solutions ) { # print the solutions print "\n--- solution $n ---\n"; sudoku_print( $solution ); } Requirements: · Perl Limitations: · This module can only solve 9x9-Sudokus. No bugs have been reported.


Games::Sudoku::Solver Related Software