Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Union of overlapping numeric intervals

by atcroft (Abbot)
on Dec 30, 2013 at 22:50 UTC ( [id://1068782]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    perl -Mstrict -Mwarnings -le 'my @l = ( q{a:10-34 b:9-12 c:12-24 e: 1-
    +9}, q{a:1-8 a: 19-24 b:2-6}, q{a:7-11 d:9-23 e:12-23} ); foreach my $
    +m ( @l ) { foreach my $n ( $m =~ m/([a-z]:\s*\d+(?:\s*-\s*\d+))/ig ) 
    +{ $n =~ s/\s+//g; print $n; } }'
    
  2. or download this
    perl -Mstrict -Mwarnings -le 'my $str = q{a:1}; my %f; $str =~ m/([a-z
    +]):(\d+)(?:-(\d))?/; my ( $k, $starting, $ending ) = ( $1, $2, define
    +d $3 ? $3 : $2 ); print $k; print $starting; print $ending;'
    
  3. or download this
    perl -Mstrict -Mwarnings -MData::Dumper -le '$Data::Dumper::Sortkeys =
    + 1; my %range = ( start => 1, end => 9, ); my %f; foreach my $i ( $ra
    +nge{start} .. $range{end} ) { $f{$i}++; } print Data::Dumper->Dump( [
    + \%f, ], [ qw( *f ) ] );'
    
  4. or download this
    perl -Mstrict -Mwarnings -le 'my %g = ( 1 => 1, 2 => 2, 3 => 2, 4 => 2
    +, 6 => 1, 7 => 1, 8 => 1, 12 => 1, ); my @h = sort { $a <=> $b } keys
    + %g; my $sv; my $ev; while ( scalar @h ) { my $v = shift @h; if ( ! d
    +efined $sv ) { $sv = $v; } if ( ! defined $ev ) { $ev = $v; } my $i =
    + 1; while ( scalar @h and $h[0] == $sv + $i ) { $i++; $ev = shift @h;
    + } if ( $sv == $ev ) { print $sv; } else { print $sv, q{ - }, $ev; } 
    +$sv = undef; $ev = undef; }'
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1068782]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-24 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found