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

DWIM is Perl's answer to Gödel

In reply to Re^3: interleaved lists check by GrandFather
in thread interleaved lists check by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.