Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Calculate the overlap length between two ranges

by sundialsvc4 (Monsignor)
on Oct 30, 2013 at 14:19 UTC ( #1060384=note: print w/ replies, xml ) Need Help??


in reply to Calculate the overlap length between two ranges

Two ranges A and B overlap if low(A) <= high(B) AND high(A) >= low(B) ... hope I got that right, but it’s something like that.   Yes, there should be a CPAN module as-noted which does this simple task and probably others that will be of interest to you.

Then, again IIRC, the distance ought to be something like Max(Low(A), High(B)) - Min(Low(B), High(A)) ... not so sure about that one, it’s been a while.   Anyway, I do remember that you are testing the opposite-end numbers in each pair in some way.


Comment on Re: Calculate the overlap length between two ranges
Re^2: Calculate the overlap length between two ranges
by Laurent_R (Vicar) on Oct 30, 2013 at 18:04 UTC

    Except that the OP did not speak about distance but about "the length between some overlapping numerical ranges", this phrasing does not really make sense to me. The length between overlapping ranges, if anything, is 0. This is why I kindly asked for clarification. Or, perhaps, it is a deficiency in my command of the English language. But the OP answered some later posts by other monks, but did not see it fit to answer mine.

Log In?
Username:
Password:

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

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

    When choosing user names for websites, I prefer to use:








    Results (223 votes), past polls