Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Itatsumaki's scratchpad

by Itatsumaki (Friar)
on Jun 02, 2004 at 14:49 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (None)
    As of 2024-04-25 03:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found