Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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.


Comment on Re: Calculate overlap between 2 ranges of numbers
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-09-30 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (383 votes), past polls