Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

# Math::Combinatorics 0.09

Date Added: July 06, 2010  |  Visits: 882

Math::Combinatorics is a Perl module that can 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 "permutations of 3 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 permutations of 3 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 object-oriented approach consumes much less memory for large sets..

 Requirements: No special requirements Platforms: Linux Keyword: B C,  Combinations,  Combinations And Permutations,  Libraries,  Mathcombinatorics,  Perl Module,  Permutations,  Print,  Programming Users rating: 0/10