Here's my crack at this interesting and deceptively difficult problem:

#! perl -slw use strict; use Data::Dump qw[ pp ]; sub dt2int { my( $d, $h, $m ) = unpack '(A2)*', $_[0]; return ( ( $d - 1 ) * 24 + $h ) * 60 + $m; } sub int2dt { sprintf "%02d%02d%02d", int($_[0]/1440)+1, int($_[0]/60)%24, $_[0] +%60; } sub adjacentPairs (&@) { my $code = shift; map { $code->( shift(), $_[0] ); } 1 .. @_; } my @listone = (['010000','010010',2],['010200','010210',5],['012359','020001',3] +); my @listtwo = (['010005','010015',1],['010207','010211',4]); my @res = adjacentPairs{ defined( $_[1] ) && $_[0][4] > $_[1][3] ? [ $_[0][0], int2dt( $_[1][3] - 1 ), $_[0][2] ] : [ @{ $_[0] }[ 0 .. 2 ] ] } sort { $a->[ 3 ] <=> $b->[ 3 ] } map { my $s = dt2int( $_->[ 0 ] ); my $e = dt2int( $_->[ 1 ] ); my @out; while( int( $s / 1440 ) != int( $e / 1440 ) ) { my $newe = ( $s + 1440 ) % 1440; push @out, [ int2dt( $s ), int2dt( $newe ), $_->[2], $s, $newe + ]; $s = $newe +1; } ( @out, [ int2dt( $s ), $_->[1], $_->[2], $s, $e ] ); } @listone, @listtwo; pp \@res; __END__ c:\test>junk33 [ ["010000", "010004", 2], ["010005", "010015", 1], ["010200", "010206", 5], ["010207", "010211", 4], ["012359", "012359", 3], ["020000", "020001", 3], ]

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Date Array Convolution by BrowserUk
in thread Date Array Convolution by alanonymous

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.