Subject: | next_permutation() returns same thing many times |
The permutation code seems to be completely broken. The sample input of
three strings (A B C) for a count of 2 works, but any longer list
results in massively redundant output. For (A B C D) it returns every
pair twice; for (A B C D E) it returns every pair SIX times!?! Try this
code:
use Math::Combinatorics;
my @as = qw( A B C D E );
my $ras = \@as;
my $oPermuter = new Math::Combinatorics(
compare => sub { $_[0] cmp $_[1] },
count => 2,
data => $ras,
);
PERMUTATION:
while (my ($sWord1, $sWord2) = $oPermuter->next_permutation)
{
print STDERR " DDD permutation is ==$sWord1==$sWord2==\n";
} # while
__END__