This still sounds like an answer to the wrong problem. For even modest sized lists the number of permutations is huge. However the following code using Math::Combinatorics should get you started:
use strict;
use warnings;
use Math::Combinatorics;
my @listA = qw(first second third);
my @listB = qw(1 2 3);
my $permA = Math::Combinatorics->new (data => [@listA]); # Note copy
while (1) {
my @listAperm = $permA->next_permutation ();
last if ! @listAperm;
my $permB = Math::Combinatorics->new (data => [@listB]); # Note co
+py
while (1) {
my @listBperm = $permB->next_permutation ();
last if ! @listBperm;
my @interList1;
my @interList2;
my $aIndex = 0;
my $bIndex = 0;
while ($aIndex < @listAperm || $bIndex < @listBperm) {
push @interList1, $listAperm[$aIndex] if $aIndex < @listAp
+erm;
push @interList2, $listBperm[$bIndex] if $bIndex < @listBp
+erm;
push @interList2, $listAperm[$aIndex++] if $aIndex < @list
+Aperm;
push @interList1, $listBperm[$bIndex++] if $bIndex < @list
+Bperm;
}
print "@interList1\n";
print "@interList2\n";
}
}
DWIM is Perl's answer to Gödel
|