[Tutor] overlap of ranges
János Juhász
janos.juhasz at VELUX.com
Wed May 4 08:09:23 CEST 2005
Hi All,
one of my colleague asked me, about how the overlap of two ranges can be
calculated easily.
>>> a = (24,27) # range1 (endpoint1,endpoint2)
>>> b = (10,227) # range1 (endpoint1,endpoint2)
>>> min( max(a), max(b) ) - max( min(a), min(b) )
3
When the result is positive, then the two ranges overlap together.
When the result is negative, then the two ranges doesn't overlap together
and the distance between them is the result multiplied with -1.
As we are using max() and min(), a=(24,27) means the same as a=(27,24).
I haven't seen this calculation method before, and I think it could be
interesting and usefull for coders.
Best regards,
János
More information about the Tutor
mailing list