Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Calculate the overlap length between two ranges

by sundialsvc4 (Abbot)
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

Replies are listed 'Best First'.
Re^2: Calculate the overlap length between two ranges
by Laurent_R (Canon) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1060384]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2018-06-21 13:36 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.