Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 perusing the Monastery: (6)
As of 2020-12-01 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (7 votes). Check out past polls.

    Notices?