Dennis Lee Bieber
3/13/2008 3:36:00 AM
On Tue, 11 Mar 2008 23:30:16 -0700 (PDT), Magdoll <magdoll@gmail.com>
declaimed the following in comp.lang.python:
> As someone else pointed out, I can't merge (1,30), (29,40) because N =
> 5. If N were always 1, I could've easily used IntervalSet to do this
> and I would not have to write more than 5 lines total to get this
> done. I'm asking precisely because N can be varied and maybe in the
> future will be more complex than just an integer.
>
Somehow I'd missed that particular constraint...
> >
> > Since this feels like a homework assignment, I won't be posting my
> > code...
>
> It isn't an homework assignment. I'm writing it for my research. Or
> more precisely, I've already written a solution and wanted to see if
> any people here know more salient solutions than mine
>
Okay -- it just came across as the type of problem one might find as
homework. In the absence of code and a discrete request for "what is
wrong" I felt it better to avoid posting my own code...
A few minutes did get my code to work with a "length of overlap"
constraint... Note that a literal reading of that requirement means that
a short interval, totally contained within a longer interval, will NOT
be merged if it does not have the required number of elements.
>pythonw -u "Intervals.py"
Testing with required overlap of 0
Final list of intervals:
(1, 15)
(20, 40)
(50, 100)
(110, 120)
(250, 260)
(300, 311)
(319, 330)
(340, 370)
Testing with required overlap of 1
Final list of intervals:
(1, 15)
(20, 40)
(50, 100)
(110, 120)
(250, 260)
(300, 311)
(319, 330)
(340, 370)
Testing with required overlap of 2
Final list of intervals:
(1, 15)
(20, 40)
(50, 100)
(110, 120)
(250, 260)
(300, 311)
(319, 330)
(340, 350)
(350, 360)
(360, 370)
Testing with required overlap of 3
Final list of intervals:
(1, 15)
(20, 30)
(29, 40)
(50, 100)
(110, 120)
(250, 260)
(300, 311)
(319, 330)
(340, 350)
(350, 360)
(360, 370)
Testing with required overlap of 4
Final list of intervals:
(1, 15)
(20, 30)
(29, 40)
(50, 100)
(110, 120)
(113, 115)
(250, 260)
(300, 311)
(319, 330)
(340, 350)
(350, 360)
(360, 370)
Testing with required overlap of 5
Final list of intervals:
(1, 15)
(20, 30)
(29, 40)
(50, 100)
(110, 120)
(113, 115)
(250, 260)
(300, 311)
(319, 330)
(340, 350)
(350, 360)
(360, 370)
>Exit code: 0
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com wulfraed@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-asst@bestiaria.com)
HTTP://www.bestiaria.com/