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"; } }
first 1 third 2 second 3 1 first 2 third 3 second first 1 third 3 second 2 1 first 3 third 2 second first 2 third 1 second 3 2 first 1 third 3 second first 2 third 3 second 1 2 first 3 third 1 second first 3 third 1 second 2 3 first 1 third 2 second first 3 third 2 second 1 3 first 2 third 1 second first 2 second 3 third 1 2 first 3 second 1 third first 2 second 1 third 3 2 first 1 second 3 third first 3 second 2 third 1 3 first 2 second 1 third first 3 second 1 third 2 3 first 1 second 2 third first 1 second 2 third 3 1 first 2 second 3 third first 1 second 3 third 2 1 first 3 second 2 third third 3 first 1 second 2 3 third 1 first 2 second third 3 first 2 second 1 3 third 2 first 1 second third 1 first 3 second 2 1 third 3 first 2 second third 1 first 2 second 3 1 third 2 first 3 second third 2 first 3 second 1 2 third 3 first 1 second third 2 first 1 second 3 2 third 1 first 3 second third 1 second 3 first 2 1 third 3 second 2 first third 1 second 2 first 3 1 third 2 second 3 first third 3 second 1 first 2 3 third 1 second 2 first third 3 second 2 first 1 3 third 2 second 1 first third 2 second 1 first 3 2 third 1 second 3 first third 2 second 3 first 1 2 third 3 second 1 first second 3 first 2 third 1 3 second 2 first 1 third second 3 first 1 third 2 3 second 1 first 2 third second 2 first 3 third 1 2 second 3 first 1 third second 2 first 1 third 3 2 second 1 first 3 third second 1 first 3 third 2 1 second 3 first 2 third second 1 first 2 third 3 1 second 2 first 3 third second 1 third 2 first 3 1 second 2 third 3 first second 1 third 3 first 2 1 second 3 third 2 first second 2 third 1 first 3 2 second 1 third 3 first second 2 third 3 first 1 2 second 3 third 1 first second 3 third 1 first 2 3 second 1 third 2 first second 3 third 2 first 1 3 second 2 third 1 first
In reply to Re^3: interleaved lists check
by GrandFather
in thread interleaved lists check
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |