Algorithm-X-DLX
view release on metacpan or search on metacpan
examples/dlx.pl view on Meta::CPAN
print "\n";
}
sub HELP_MESSAGE {
my $script = $0;
$script =~ s|^.*/||;
print<<HELP
Usage: $script -[options] <input>
Option flags are:
-p print solutions as a line with selected row indices
-v print solutions by outputting the rows themselves
-t print nodes inspected for each recursion level
-s input is a sparse matrix
The first line of input states the problem matrix width (all columns), optionally
followed by a space and the number of secondary columns therein, at the right.
All following lines are the matrix rows (space separated).
HELP
examples/sudoku/sudoku.pl view on Meta::CPAN
use SudokuSolver;
use SudokuType;
sub HELP_MESSAGE {
my $script = $0;
$script =~ s|^.*/||;
print<<HELP
Usage: $script -[options|f:format] <input>
Option flags are:
-h print help
-l input has 1 puzzle per line
-v print solution underneath the puzzle, not side by side
-s print solutions only, not the puzzle
Output format options (-f) are:
'preserve' (default): stick to the input format
'oneline': all cell values concatenated
'compact': cells only, omitting regions
'default': vanilla 9x9
lib/Algorithm/X/Examples.pod view on Meta::CPAN
You would have to call them manually.
$ prove examples/t/*
=head2 Example: dlx
L<examplesE<sol>dlx.pl|https://metacpan.org/dist/Algorithm-X-DLX/source/examples/dlx.pl> is a simple command-line program that reads an exact cover problem from stdin and solves it.
The first line of stdin contains the number of columns, and the following lines contain the rows of the matrix.
Output can be controlled by flags. By default, only the number of solutions is printed.
If C<-p> is given, every solution is printed on its own line by giving the indices of the selected rows.
With C<-v>, the full rows are printed.
examples$ ./dlx.pl -pv < data/knuth_example.txt
1 0 0 1 0 0 0
0 0 1 0 1 1 0
0 1 0 0 0 0 1
solutions: 1
lib/Algorithm/X/Examples.pod view on Meta::CPAN
=back
The first one can actually be either a secondary or a primary column; if all other conditions are met, every cell will naturally contain I<at most one> digit.
Each row of the matrix hits exactly one column of each type.
For the standard 9x9 Sudoku, all regions are 3x3 squares. But it is straight-forward to generalize this so that the regions can form an arbitrary partition of the grid to subsets of size n. This also makes it possible to create Sudokus of any size; w...
=head3 Usage
The executable tries to infer as much as possible from the input data, requiring no flags or meta data about the Sudoku types. It expects to find Sudokus separated by empty lines. Empty cells can be either dots (C<'.'>) or zeros (C<'0'>). All non-zer...
The given Sudokus will be solved, unless they are invalid or unsolvable; in that case, an error message is printed. A completely empty Sudoku will be replaced with a randomly generated (and usually quite difficult) one, which is also solved.
=head3 Examples
examples/sudoku$ perl -I. ./sudoku.pl < ../data/sudoku.txt*
examples/sudoku$ perl -I. ./sudoku.pl -s -l -f oneline < sudoku17** > sudoku17_solutions
examples/sudoku$ yes . | head -n81 | perl -I. ./sudoku.pl -f default
( run in 1.886 second using v1.01-cache-2.11-cpan-94b05bcf43c )