Algorithm-X-DLX
view release on metacpan or search on metacpan
lib/Algorithm/X/Examples.pod view on Meta::CPAN
..Q.
Q...
...Q
.Q..
.Q..
...Q
Q...
..Q.
=head2 Example: Langford pairings
See L<https://en.wikipedia.org/wiki/Langford_pairing>.
examples/langford$ perl -I. langford.pl -v 1 2 3 4 5
Solutions for n = 1: 0
Solutions for n = 2: 0
Solutions for n = 3: 1
3 1 2 1 3 2
Solutions for n = 4: 1
4 1 3 1 2 4 3 2
Solutions for n = 5: 0
=head2 Example: N-pieces
Generalized version of N-queens: place N knights and Q queens on an AxB board. Quite slow, unfortunately.
examples/npieces$ perl -I. npieces.pl 8 8 5 5
Solution 1
NN......
....Q...
......Q.
NN......
N.......
.......Q
.....Q..
..Q.....
< snip >
Solutions for 8x8, N=5, Q=5: 16
entire L<output|https://metacpan.org/dist/Algorithm-X-DLX/source/examples/npieces/npieces-solutions.txt>
=head2 Example: Polyominoes
The code can solve any polyomino puzzle, but for now the executable simply prints all solutions to Scott's pentomino problem:
examples/polyomino$ perl -I. polyomino.pl | head -n8
LLXCCVVV
LXXXCVZZ
LNXCCVZY
LNT ZZY
NNT WYY
NTTTWWFY
PPPWWFFF
PPIIIIIF
entire L<output|https://metacpan.org/dist/Algorithm-X-DLX/source/examples/polyomino/solutions-to-scotts-pentomino.txt>
=head1 DISCLAIMER
Author of the originating C++ sources, of which this distribution is mostly a direct translation,
is Johannes Laire at L<https://github.com/jlaire/dlx-cpp>.
Even all the examples, tests and most of the documentation are his.
=head1 COPYRIGHT AND LICENSE
The following copyright notice applies to all the files provided in
this distribution, unless explicitly noted otherwise.
This software is copyright (c) 2025 by Steffen Heinrich
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
=head1 SEE ALSO
Donald E. Knuth, Stanford University 2000 L<Dancing Links|http://arxiv.org/pdf/cs/0011047v1>
L<Introduction to Exact Cover Problem and Algorithm X|https://www.geeksforgeeks.org/introduction-to-exact-cover-problem-and-algorithm-x/>
Peter Pfeiffer BSc, Linz 2023 L<Uncovering Exact Cover Encodings|https://epub.jku.at/obvulihs/download/pdf/9260418>
=cut
( run in 0.323 second using v1.01-cache-2.11-cpan-5623c5533a1 )