~ubuntu-branches/ubuntu/trusty/horae/trusty

« back to all changes in this revision

Viewing changes to 0CPAN/Math-Combinatorics-0.08/README

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
NAME
2
 
    Math::Combinatorics - Perform combinations and permutations on lists
3
 
 
4
 
SYNOPSIS
5
 
    Available as an object oriented API.
6
 
 
7
 
      use Math::Combinatorics;
8
 
 
9
 
      my @n = qw(a b c);
10
 
      my $combinat = Math::Combinatorics->new(count => 2,
11
 
                                              data => [@n],
12
 
                                             );
13
 
 
14
 
      print "combinations of 2 from: ".join(" ",@n)."\n";
15
 
      print "------------------------".("--" x scalar(@n))."\n";
16
 
      while(my @combo = $combinat->next_combination){
17
 
        print join(' ', @combo)."\n";
18
 
      }
19
 
 
20
 
      print "\n";
21
 
 
22
 
      print "combinations of 2 from: ".join(" ",@n)."\n";
23
 
      print "------------------------".("--" x scalar(@n))."\n";
24
 
      while(my @permu = $combinat->next_permutation){
25
 
        print join(' ', @permu)."\n";
26
 
      }
27
 
 
28
 
      output:
29
 
 
30
 
    Or available via exported functions 'permute', 'combine', and
31
 
    'factorial'.
32
 
 
33
 
      use Math::Combinatorics;
34
 
 
35
 
      my @n = qw(a b c);
36
 
      print "combinations of 2 from: ".join(" ",@n)."\n";
37
 
      print "------------------------".("--" x scalar(@n))."\n";
38
 
      print join("\n", map { join " ", @$_ } combine(2,@n)),"\n";
39
 
      print "\n";
40
 
      print "permutations of 3 from: ".join(" ",@n)."\n";
41
 
      print "------------------------".("--" x scalar(@n))."\n";
42
 
      print join("\n", map { join " ", @$_ } permute(@n)),"\n";
43
 
 
44
 
    Output:
45
 
 
46
 
      combinations of 2 from: a b c
47
 
      ------------------------------
48
 
      a b
49
 
      a c
50
 
      b c
51
 
 
52
 
      combinations of 2 from: a b c
53
 
      ------------------------------
54
 
      a b c
55
 
      a c b
56
 
      b a c
57
 
      b c a
58
 
      c a b
59
 
      c b a
60
 
 
61
 
    Output from both types of calls is the same, but the object-oriented
62
 
    approach consumes much less memory for large sets.
63
 
 
64
 
DESCRIPTION
65
 
    Combinatorics is the branch of mathematics studying the enumeration,
66
 
    combination, and permutation of sets of elements and the mathematical
67
 
    relations that characterize their properties. As a jumping off point,
68
 
    refer to:
69
 
 
70
 
    http://mathworld.wolfram.com/Combinatorics.html
71
 
 
72
 
    This module provides a pure-perl implementation of nCk, nPk, and n!
73
 
    (combination, permutation, and factorial, respectively). Functional and
74
 
    object-oriented usages allow problems such as the following to be
75
 
    solved:
76
 
 
77
 
    nCk "Fun questions to ask the pizza parlor wait staff: how many possible
78
 
    combinations of 2 toppings can I get on my pizza?".
79
 
 
80
 
    nPk "Master Mind Game: ways to arrange pieces of different colors in a
81
 
    certain number of positions, without repetition of a color".
82
 
 
83
 
    Object-oriented usage additionally allows solving these problems by
84
 
    calling the new() entry elsewhere in this document with a frequency
85
 
    vector:
86
 
 
87
 
    nPRk "morse signals: diferent signals of 3 positions using the 2 two
88
 
    symbol - and .".
89
 
 
90
 
    nCRk "ways to extract 3 balls at once of a bag with black and white
91
 
    balls".
92
 
 
93
 
    nPRk "different words obtained permuting the letters of the word
94
 
    PARROT".
95
 
 
96
 
AUTHOR
97
 
    Allen Day <allenday@ucla.edu>, with algorithmic contributions from
98
 
    Christopher Eltschka and Tye.
99
 
 
100
 
ACKNOWLEDGEMENTS
101
 
    Thanks to everyone for helping to make this a better module.
102
 
 
103
 
    For adding new features: Carlos Rica, David Coppit
104
 
 
105
 
    For bug reports: Ying Yang, Joerg Beyer, Marc Logghe
106
 
 
107
 
LICENSE AND COPYRIGHT
108
 
 
109
 
    Copyright (c) 2004 Allen Day. All rights reserved. This program is
110
 
    free software; you can redistribute it and/or modify it under the same
111
 
    terms as Perl itself.