Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Calculate overlap between 2 ranges of numbers

by jdporter (Canon)
on Oct 22, 2011 at 21:40 UTC ( #933106=note: print w/replies, xml ) Need Help??


in reply to Calculate overlap between 2 ranges of numbers

You could use Set::IntSpan:

use Set::IntSpan; my $r1 = Set::IntSpan->new([ 5 .. 15 ]); my $r2 = Set::IntSpan->new([ 2 .. 20 ]); my $i = $r1->intersect($r2); if ( !$i->empty and ( $i->max - $i->min ) >= 5 ) # criteria { print "hit\n"; } else { print "miss\n"; }
I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://933106]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2016-12-05 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (72 votes). Check out past polls.