line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 Name |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Math::Permute::Partitions - Generate all the permutations of a partitioned list. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 Synopsis |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Math::Permute::Partitions; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
permutePartitions {$a .= "@_\n"} [1,2], [3,4]; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# 1 2 3 4 |
12
|
|
|
|
|
|
|
# 1 2 4 3 |
13
|
|
|
|
|
|
|
# 2 1 3 4 |
14
|
|
|
|
|
|
|
# 2 1 4 3 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
15221
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Math::Permute::Partitions; |
21
|
1
|
|
|
1
|
|
412
|
use Math::Permute::List; |
|
1
|
|
|
|
|
298
|
|
|
1
|
|
|
|
|
59
|
|
22
|
1
|
|
|
1
|
|
488
|
use Math::Cartesian::Product; |
|
1
|
|
|
|
|
437
|
|
|
1
|
|
|
|
|
175
|
|
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
2
|
0
|
561
|
sub permutePartitions(&@) # Generate permutations of a partitioned list |
25
|
|
|
|
|
|
|
{my $s = shift; # Subroutine to call to process each permutation |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
2
|
my @p; # Partitions |
28
|
2
|
|
|
|
|
3
|
my $p = 0; # Current partitions |
29
|
2
|
|
|
|
|
4
|
for(@_) |
|
14
|
|
|
|
|
31
|
|
30
|
5
|
|
|
14
|
|
19
|
{permute {push @{$p[$p]}, [@_]} @$_; # Permute each partition |
|
14
|
|
|
|
|
202
|
|
31
|
5
|
|
|
|
|
65
|
++$p; |
32
|
|
|
|
|
|
|
} |
33
|
2
|
|
|
28
|
|
10
|
cartesian {&$s(map {@$_} @_)} @p; # form cartesian product of permutations of each partition |
|
28
|
|
|
|
|
316
|
|
|
80
|
|
|
|
|
94
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Export details |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
require 5; |
39
|
|
|
|
|
|
|
require Exporter; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
6
|
use vars qw(@ISA @EXPORT $VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
74
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
44
|
|
|
|
|
|
|
@EXPORT = qw(permutePartitions); |
45
|
|
|
|
|
|
|
$VERSION = '1.001'; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 Description |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Generate all the permutations of a partitioned list using the standard |
50
|
|
|
|
|
|
|
Perl metaphor. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
C returns the number of permutations in both scalar and array |
53
|
|
|
|
|
|
|
context. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
C is written in 100% Pure Perl. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 Export |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The C function is exported. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 Installation |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Standard Module::Build process for building and installing modules: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
perl Build.PL |
67
|
|
|
|
|
|
|
./Build |
68
|
|
|
|
|
|
|
./Build test |
69
|
|
|
|
|
|
|
./Build install |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Or, if you're on a platform (like DOS or Windows) that doesn't require |
72
|
|
|
|
|
|
|
the "./" notation, you can do this: |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
perl Build.PL |
75
|
|
|
|
|
|
|
Build |
76
|
|
|
|
|
|
|
Build test |
77
|
|
|
|
|
|
|
Build install |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 Author |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
PhilipRBrenan@appaapps.com |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
http://www.appaapps.com |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 Acknowledgements |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Based on an idea from Philipp Rumpf |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 See Also |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=over |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item L |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item L |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item L |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item L |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item L |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item L |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item L |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=back |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 Copyright |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Copyright (c) 2015 Philip R Brenan. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This module is free software. It may be used, redistributed and/or |
114
|
|
|
|
|
|
|
modified under the same terms as Perl itself. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |