Re: Determing whether two ranges overlap

2006-02-22 Thread Magnus Lycka
Fredrik Lundh wrote: > def overlap(a, b): > return a[1] > b[0] and a[0] < b[1] Assuming that x[1] can't be smaller than x[0], this is the right way to compare two ranges. Well, I guess you need to figure out the borderline cases. Is it a[1] > b[0] or a[1] >= b[0] which is relevant? An

Re: Determing whether two ranges overlap

2006-02-17 Thread Ralf Muschall
Robin Haswell wrote: > I can think of lots of ways to do this but it's in a tight loop so I need > it to be as efficient as possible. Any help welcome :-) There are 24 possibilities of having 4 numbers in a row, and the following 6 of them describe nonempty intervals (the remaining 18 are obtaine

Re: Determing whether two ranges overlap

2006-02-17 Thread Robin Haswell
Thanks guys, you've all been very helpful :-) -Rob -- http://mail.python.org/mailman/listinfo/python-list

Re: Determing whether two ranges overlap

2006-02-17 Thread Paul McGuire
Robin Haswell wrote: > Hey guys > > I was wondering if you could give me a hand with something. If I have two > tuples that define a range, eg: (10, 20), (15, 30), I need to determine > whether the ranges overlap each other. def overlap(a,b): return a[0] <= b[0] <= a[1] or b[0] <= a[0] <= b[1

Re: Determing whether two ranges overlap

2006-02-16 Thread Fredrik Lundh
Robin Haswell wrote: > I was wondering if you could give me a hand with something. If I have two > tuples that define a range, eg: (10, 20), (15, 30), I need to determine > whether the ranges overlap each other. The algo needs to catch: > > (10, 20) (15, 25) > (15, 25) (10, 20) > (10, 25) (15, 20)

RE: Determing whether two ranges overlap

2006-02-16 Thread Tim Golden
[Robin Haswell] | I was wondering if you could give me a hand with something. | If I have two | tuples that define a range, eg: (10, 20), (15, 30), I need to | determine | whether the ranges overlap each other. The algo needs to catch: | | (10, 20) (15, 25) | (15, 25) (10, 20) | (10, 25) (15, 2

Re: Determing whether two ranges overlap

2006-02-16 Thread Steven D'Aprano
On Thu, 16 Feb 2006 15:22:15 +, Robin Haswell wrote: > Hey guys > > I was wondering if you could give me a hand with something. If I have two > tuples that define a range, eg: (10, 20), (15, 30), I need to determine > whether the ranges overlap each other. The algo needs to catch: > > (10, 2

Determing whether two ranges overlap

2006-02-16 Thread Robin Haswell
Hey guys I was wondering if you could give me a hand with something. If I have two tuples that define a range, eg: (10, 20), (15, 30), I need to determine whether the ranges overlap each other. The algo needs to catch: (10, 20) (15, 25) (15, 25) (10, 20) (10, 25) (15, 20) and (15, 20) (10, 25) I