On May 22, 2006, at 20:14, Xavier Noria wrote:
That takes advantage of the fact that we want to divide a given set
in just two subsets of fixed size. A partitions generator may be
added to the module soon, but until then I think there's room for
Set::Partition.
Indeed, I just uploaded to PAUSE Algorithm::Combinatorics 0.15 with
generators of partitions, and partitions of a given size.
To solve the original problem with these subroutines one generates
partitions of size 2 and filters out those whose subsets have size
1/4, as in the session copied below.
-- fxn
% cat foo.pl
use strict;
use warnings;
use Algorithm::Combinatorics qw(partitions);
my @data = qw(a b c d e);
my $iter = partitions([EMAIL PROTECTED], 2);
while (my $p = $iter->next) {
next unless @{$p->[0]} == 2 || @{$p->[0]} == 3;
print "(@$_)" for @$p;
print "\n";
}
% perl foo.pl
(a b c)(d e)
(a b d)(c e)
(a b e)(c d)
(a b)(c d e)
(a c d)(b e)
(a c e)(b d)
(a c)(b d e)
(a d e)(b c)
(a d)(b c e)
(a e)(b c d)