1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

NAME
Math::Combinatorics  Perform combinations and permutations on lists
SYNOPSIS
Available as an object oriented API.
use Math::Combinatorics;
my @n = qw(a b c);
my $combinat = Math::Combinatorics>new(count => 2,
data => [@n],
);
print "combinations of 2 from: ".join(" ",@n)."\n";
print "".("" x scalar(@n))."\n";
while(my @combo = $combinat>next_combination){
print join(' ', @combo)."\n";
}
print "\n";
print "combinations of 2 from: ".join(" ",@n)."\n";
print "".("" x scalar(@n))."\n";
while(my @permu = $combinat>next_permutation){
print join(' ', @permu)."\n";
}
output:
Or available via exported functions 'permute', 'combine', and
'factorial'.
use Math::Combinatorics;
my @n = qw(a b c);
print "combinations of 2 from: ".join(" ",@n)."\n";
print "".("" x scalar(@n))."\n";
print join("\n", map { join " ", @$_ } combine(2,@n)),"\n";
print "\n";
print "permutations of 3 from: ".join(" ",@n)."\n";
print "".("" x scalar(@n))."\n";
print join("\n", map { join " ", @$_ } permute(@n)),"\n";
Output:
combinations of 2 from: a b c

a b
a c
b c
combinations of 2 from: a b c

a b c
a c b
b a c
b c a
c a b
c b a
Output from both types of calls is the same, but the objectoriented
approach consumes much less memory for large sets.
DESCRIPTION
Combinatorics is the branch of mathematics studying the enumeration,
combination, and permutation of sets of elements and the mathematical
relations that characterize their properties. As a jumping off point,
refer to:
http://mathworld.wolfram.com/Combinatorics.html
This module provides a pureperl implementation of nCk, nPk, and n!
(combination, permutation, and factorial, respectively). Functional and
objectoriented usages allow problems such as the following to be
solved:
nCk "Fun questions to ask the pizza parlor wait staff: how many possible
combinations of 2 toppings can I get on my pizza?".
nPk "Master Mind Game: ways to arrange pieces of different colors in a
certain number of positions, without repetition of a color".
Objectoriented usage additionally allows solving these problems by
calling the new() entry elsewhere in this document with a frequency
vector:
nPRk "morse signals: diferent signals of 3 positions using the 2 two
symbol  and .".
nCRk "ways to extract 3 balls at once of a bag with black and white
balls".
nPRk "different words obtained permuting the letters of the word
PARROT".
AUTHOR
Allen Day <allenday@ucla.edu>, with algorithmic contributions from
Christopher Eltschka and Tye.
ACKNOWLEDGEMENTS
Thanks to everyone for helping to make this a better module.
For adding new features: Carlos Rica, David Coppit
For bug reports: Ying Yang, Joerg Beyer, Marc Logghe
LICENSE AND COPYRIGHT
Copyright (c) 2004 Allen Day. All rights reserved. This program is
free software; you can redistribute it and/or modify it under the same
terms as Perl itself.
