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

Itatsumaki's scratchpad

by Itatsumaki (Friar)
on Jun 02, 2004 at 14:49 UTC ( #359469=scratchpad: print w/replies, xml ) Need Help??

# This code gets the overlap between two closed ranges: # R1 = [$L1, $U1] # and R2 = [$L2, $U2] # parameters my $L1 = 5; my $L2 = -33; my $U1 = 10; my $U2 = 10; # result my $common; # if R1 ends somewhere in R2 if (($U1 >= $L2) && ($U1 <= $U2)) { # make sure to use smallest lower boundary ($L1 > $L2) ? ( $common = $U1 - $L1) : ($common = $U1 - $L2); $common++; } # elsif R2 ends somewhere in R1 elsif (($U2 >= $L1) && ($U2 <= $U1)) { # make sure to use smallest lower boundary ($L1 > $L2) ? ( $common = $U2 - $L1) : ($common = $U2 - $L2); $common++; } # else no match else { $common = 0; } print "Common: $common\n";
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2020-02-24 07:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (104 votes). Check out past polls.

    Notices?