I want to compute the overlap fraction of two numeric ranges. Let me illustrate my question with an example since I believe that it will be easier to understand.
Lets say that I have two numeric ranges:
A = [1,100]
B = [25,100]
What I want to know (and code) is how much is B overlapping A and viceversa (how much is A overlapping B)
In this case, A overlaps B (as a fraction of B) by 100% and B overlaps A (as a fraction of A) by 75% percent.
I have try been trying to code this in python, but I am struggling and I can't find the proper solution for computing both fractions
What I have been able to achieve so far is the following:
Given the start and end of both numeric ranges, I have been able to figure out if the two numerical ranges overlap (from other stackoverflow post)
I have done this with the following code
def is_overlapping(x1,x2,y1,y2):
return max(x1,y1) <= min(x2,y2)
thanks!