Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2022-05-25 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?