Has anyone encountered and/or developed a Perl-based solution to the following problem?

You have 2 or more lists, each holding 1 or more strictly increasing integers. None of the lists intersect with any of the others. There may be gaps between the last (highest) value of one list and the first (lowest) value of the next list (next in the sense of the lists being ordered by their lowest values). Example:

(1..17); (25..42); (44..50);

Given two non-equal integers, m and n, generate a list of all integers between by concatenating (a) the already extant lists, or parts thereof; and (b) new lists to supply integers falling (i) below the first list, (ii) between any two extant lists, or (iii) above the last list.

With the lists above, and given:

m = 12; n = 62;

then the list (12 .. 62) would be built up from the following components:

(12..17); # sublist of the 1st list (18..24); # gap-filling list (25..42); # entirety of the 2nd list (43); # gap-filling list (44..50); # entirety of the 3rd list (51..62); # integers needed above highest list

I know I could figure this out if I had some spare cycles, but why re-invent the wheel? Thanks in advance.

Jim Keenan


In reply to Gap-filling lists by jkeenan1

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.