[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Interval relationships (Was: Re: Range#overlap?

Pit Capitain

2/21/2007 6:56:00 PM

Avdi Grimm schrieb:
> In particular I'm looking for the most straightforward way to consolidate a
> set of intervals such that the resulting set is composed of the smallest
> number of non-contiguous, non-overlapping intervals that encompass all of
> the starting intervals. E.g.:
>
> |---|
> |---|
> |---|
> |---|
> |------|
>
> would become:
>
> |---------|
> |------|

Avdi, here's one way (based on your example above):

def combine(intervals)
intervals.sort.inject([]) { |result, (from, to)|
if result.empty? or from > result.last[1]
result << [from, to]
elsif to > result.last[1]
result.last[1] = to
end
result
}
end

p combine([[0, 4], [2, 6], [6, 10], [13, 17], [12, 19]])
# => [[0, 10], [12, 19]]

Regards,
Pit

14 Answers

Rob Biedenharn

2/22/2007 3:32:00 AM

0



GLOBALIST

1/22/2013 5:24:00 PM

0

On Tuesday, January 22, 2013 9:35:20 AM UTC-6, Gary wrote:
> On Tue, 22 Jan 2013 14:31:47 +0100, Earl Evleth <evleth@wanadoo.fr>
>
> wrote:
>
>
>
> >Police: Las Vegas Cop Killed Family, Self
>
> >
>
> >Las Vegas officials said a local police officer killed his family and then
>
> >set his home on fire before eventually killing himself on Monday. Police in
>
> >Boulder City, a suburb of Las Vegas, received a call at 8:20 a.m. on Monday
>
> >from a man who said he had killed his wife and son and was planning on
>
> >setting his home on fire. While they would only confirm it was an �off-duty
>
> >Las Vegas officer,� the house belonged to Lt. Hans Walters, 52, and his
>
> >wife, Kathryn, 46. When police responded to the call, the man at the house
>
> >had a shotgun and ignored officers� warnings and entered the burning house.
>
> >The coroner confirmed three bodies were found in the house.
>
>
>
> I have no problem with people who kill themselves. But why is it so
>
> many of these bastards want to kill other people --- before killing
>
> themselves. There's been a lot of them recently. I hope the
>
> hottest spot in hell is reserved for them.

Gary,
I used to think about that, but the other folks, wife, kids, moms
are ending their lives here on earth and who knows how long they
each had to begin with. So being innocents , ironically they
may see their killer in heaven.
Crazy people are not going to hell for being crazy.
But if the lives are some are cut short, why does
it not disturb out that an infant is murdered before it
comes into it's mother's arms. That does not seem
to phase some of your folks the least.

Gary

1/22/2013 5:28:00 PM

0

On Tue, 22 Jan 2013 08:31:48 -0800 (PST), Robert
<jungleandy1@hotmail.com> wrote:

>On Jan 22, 9:35 am, Gary <n...@none.com> wrote:
> I hope the
>> hottest spot in hell is reserved for them.
>
>That one's been taken..... and I think it will be
>occupied before he finishes his second term......

As little as I think of Obama, I never think of him as being evil.
I don't think he has enough talent to be very bad. For the past
four years, he has occupied a job that would have been better
occupied by any one of (roughly) 250 million other Americans.

As I said, I don't think of him as evil. Any more than I think of
dog droppings on my lawn as evil. Ignore him. Like any other bad
dream (or fungus) -- he too -- will go away.


rumpelstiltskin

1/22/2013 8:20:00 PM

0

On Tue, 22 Jan 2013 10:35:20 -0500, Gary <nov@none.com> wrote:

>On Tue, 22 Jan 2013 14:31:47 +0100, Earl Evleth <evleth@wanadoo.fr>
>wrote:
>
>>Police: Las Vegas Cop Killed Family, Self
>>
>>Las Vegas officials said a local police officer killed his family and then
>>set his home on fire before eventually killing himself on Monday. Police in
>>Boulder City, a suburb of Las Vegas, received a call at 8:20 a.m. on Monday
>>from a man who said he had killed his wife and son and was planning on
>>setting his home on fire. While they would only confirm it was an ?off-duty
>>Las Vegas officer,? the house belonged to Lt. Hans Walters, 52, and his
>>wife, Kathryn, 46. When police responded to the call, the man at the house
>>had a shotgun and ignored officers? warnings and entered the burning house.
>>The coroner confirmed three bodies were found in the house.
>
>I have no problem with people who kill themselves. But why is it so
>many of these bastards want to kill other people --- before killing
>themselves. There's been a lot of them recently. I hope the
>hottest spot in hell is reserved for them.


It's our primal state. Such people have cast off the veneer
of civilization, and it is just a veneer. The beast that is inside
all of us has come to the surface and taken over in them.

Look what we do to cows and chickens, or fish, or whales
who are intelligent in an order comparable to our own,
without giving much thought to it. That's what we really are,
underneath the shallow mask.

We do have to stamp out the "sociopathy" when it arises
from the depths of what is inside all of us, for the sake of the
common good of mankind, but that doesn't help the other
animals. Our behaviour toward them is what we really are.

Here's Matt again:



.... The Sea of Faith
Was once, too, at the full, and round earth's shore
Lay like the folds of a bright girdle furled.
But now I only hear
Its melancholy, long, withdrawing roar,
Retreating, to the breath
Of the night-wind, down the vast edges drear
And naked shingles of the world.

Ah, love, let us be true
To one another! for the world, which seems
To lie before us like a land of dreams,
So various, so beautiful, so new,
Hath really neither joy, nor love, nor light,
Nor certitude, nor peace, nor help for pain;
And we are here as on a darkling plain
Swept with confused alarms of struggle and flight,
Where ignorant armies clash by night.

-- Matthew Arnold, from "Dover Beach"
http://www.victorianweb.org/authors/arnold/writings/dover...

GLOBALIST

1/22/2013 8:50:00 PM

0

On Tuesday, January 22, 2013 2:20:20 PM UTC-6, rumpelstiltskin wrote:
> On Tue, 22 Jan 2013 10:35:20 -0500, Gary <nov@none.com> wrote:
>
>
>
> >On Tue, 22 Jan 2013 14:31:47 +0100, Earl Evleth <evleth@wanadoo.fr>
>
> >wrote:
>
> >
>
> >>Police: Las Vegas Cop Killed Family, Self
>
> >>
>
> >>Las Vegas officials said a local police officer killed his family and then
>
> >>set his home on fire before eventually killing himself on Monday. Police in
>
> >>Boulder City, a suburb of Las Vegas, received a call at 8:20 a.m. on Monday
>
> >>from a man who said he had killed his wife and son and was planning on
>
> >>setting his home on fire. While they would only confirm it was an �off-duty
>
> >>Las Vegas officer,� the house belonged to Lt. Hans Walters, 52, and his
>
> >>wife, Kathryn, 46. When police responded to the call, the man at the house
>
> >>had a shotgun and ignored officers� warnings and entered the burning house.
>
> >>The coroner confirmed three bodies were found in the house.
>
> >
>
> >I have no problem with people who kill themselves. But why is it so
>
> >many of these bastards want to kill other people --- before killing
>
> >themselves. There's been a lot of them recently. I hope the
>
> >hottest spot in hell is reserved for them.
>
>
>
>
>
> It's our primal state. Such people have cast off the veneer
>
> of civilization, and it is just a veneer. The beast that is inside
>
> all of us has come to the surface and taken over in them.
>
>
>
> Look what we do to cows and chickens, or fish, or whales
>
> who are intelligent in an order comparable to our own,
>
> without giving much thought to it. That's what we really are,
>
> underneath the shallow mask.
>
>
>
> We do have to stamp out the "sociopathy" when it arises
>
> from the depths of what is inside all of us, for the sake of the
>
> common good of mankind, but that doesn't help the other
>
> animals. Our behaviour toward them is what we really are.
>
>
>
> Here's Matt again:
>
>
>
>
>
>
>
> ... The Sea of Faith
>
> Was once, too, at the full, and round earth's shore
>
> Lay like the folds of a bright girdle furled.
>
> But now I only hear
>
> Its melancholy, long, withdrawing roar,
>
> Retreating, to the breath
>
> Of the night-wind, down the vast edges drear
>
> And naked shingles of the world.
>
>
>
> Ah, love, let us be true
>
> To one another! for the world, which seems
>
> To lie before us like a land of dreams,
>
> So various, so beautiful, so new,
>
> Hath really neither joy, nor love, nor light,
>
> Nor certitude, nor peace, nor help for pain;
>
> And we are here as on a darkling plain
>
> Swept with confused alarms of struggle and flight,
>
> Where ignorant armies clash by night.
>
>
>
> -- Matthew Arnold, from "Dover Beach"
>
> http://www.victorianweb.org/authors/arnold/writings/dover...
+++++++++++++++++++++++++++++

You sure do love those "religious" poets, huh?

quote:
Arnold considered "religion as the highest form of culture"
end of quote
+++++++++++++++


Religious writings

Lastly Arnold turned to religion, the constant preoccupation and true centre of his whole life, and wrote St. Paul and Protestantism (1870), Literature and Dogma (1873), God and the Bible (1875), and Last Essays on Church and Religion (1877). In these books, Arnold really founded Anglican “modernism.” Like all religious liberals, he came under fire from two sides: from the orthodox, who accused him of infidelity, of turning God into a “stream of tendency” and of substituting vague emotion for definite belief; and from the infidels, for clinging to the church and retaining certain Christian beliefs of which he had undermined the foundations. Arnold considered his religious writings to be constructive and conservative. Those who accused him of destructiveness did not realize how far historical and scientific criticism had already riddled the old foundations; and those who accused him of timidity failed to see that he regarded religion as the highest form of culture, the one indispensable without which all secular education is in vain. His attitude is best summed up in his own words (from the preface to God and the Bible): “At the present moment two things about the Christian religion must surely be clear to anybody with eyes in his head. One is, that men cannot do without it; the other, that they cannot do with it as it is.” Convinced that much in popular religion was “touched with the finger of death” and convinced no less of the hopelessness of man without religion, he sought to find for religion a basis of “scientific fact” that even the positive modern spirit must accept. A reading of Arnold’s Note Books will convince any reader of the depth of Arnold’s spirituality and of the degree to which, in his “buried life,” he disciplined himself in constant devotion and self-forgetfulness.

Arnold died suddenly, of heart failure, in the spring of 1888, at Liverpool and was buried at Laleham, with the three sons whose early loss had shadowed his life.
===================

mg

1/22/2013 10:01:00 PM

0

On Jan 22, 1:20 pm, rumpelstiltskin <rumpelstilts...@x.com> wrote:
> On Tue, 22 Jan 2013 10:35:20 -0500, Gary <n...@none.com> wrote:
> >On Tue, 22 Jan 2013 14:31:47 +0100, Earl Evleth <evl...@wanadoo.fr>
> >wrote:
>
> >>Police: Las Vegas Cop Killed Family, Self
>
> >>Las Vegas officials said a local police officer killed his family and then
> >>set his home on fire before eventually killing himself on Monday. Police in
> >>Boulder City, a suburb of Las Vegas, received a call at 8:20 a.m. on Monday
> >>from a man who said he had killed his wife and son and was planning on
> >>setting his home on fire. While they would only confirm it was an off-duty
> >>Las Vegas officer, the house belonged to Lt. Hans Walters, 52, and his
> >>wife, Kathryn, 46. When police responded to the call, the man at the house
> >>had a shotgun and ignored officers warnings and entered the burning house.
> >>The coroner confirmed three bodies were found in the house.
>
> >I have no problem with people who kill themselves.   But why is it so
> >many of these bastards want to kill other people --- before killing
> >themselves.    There's been a lot of them recently.     I hope the
> >hottest spot in hell is reserved for them.
>
>    It's our primal state.  Such people have cast off the veneer
> of civilization, and it is just a veneer.  The beast that is inside
> all of us has come to the surface and taken over in them.
>
>    Look what we do to cows and chickens, or fish, or whales
> who are intelligent in an order comparable to our own,
> without giving much thought to it.  That's what we really are,
> underneath the shallow mask.
>
>    We do have to stamp out the "sociopathy" when it arises
> from the depths of what is inside all of us, for the sake of the
> common good of mankind, but that doesn't help the other
> animals.  Our behaviour toward them is what we really are.
>
>    Here's Matt again:
>
> ... The Sea of Faith
> Was once, too, at the full, and round earth's shore
> Lay like the folds of a bright girdle furled.
> But now I only hear
> Its melancholy, long, withdrawing roar,
> Retreating, to the breath
> Of the night-wind, down the vast edges drear
> And naked shingles of the world.
>
> Ah, love, let us be true
> To one another! for the world, which seems
> To lie before us like a land of dreams,
> So various, so beautiful, so new,
> Hath really neither joy, nor love, nor light,
> Nor certitude, nor peace, nor help for pain;
> And we are here as on a darkling plain
> Swept with confused alarms of struggle and flight,
> Where ignorant armies clash by night.
>
>    -- Matthew Arnold, from "Dover Beach"http://www.victorianweb.org/authors/arnold/writings/dover...

One would think that psychiatrists, by now, would have been able to
develop fairly reliable, tricky, little tests by now to identify
people (especially police officers) who are unstable, but I guess not.

Gary

1/22/2013 10:24:00 PM

0

On Tue, 22 Jan 2013 14:00:32 -0800 (PST), mg <mgkelson@yahoo.com>
wrote:

>One would think that psychiatrists, by now, would have been able to
>develop fairly reliable, tricky, little tests by now to identify
>people (especially police officers) who are unstable, but I guess not.

Unlike intelligence and syphilis, crazy doesn't show up well on a
test.

brian

1/23/2013 2:06:00 AM

0

On Tue, 22 Jan 2013 14:00:32 -0800 (PST), mg <mgkelson@yahoo.com>
wrote:

>On Jan 22, 1:20?pm, rumpelstiltskin <rumpelstilts...@x.com> wrote:
>> On Tue, 22 Jan 2013 10:35:20 -0500, Gary <n...@none.com> wrote:
>> >On Tue, 22 Jan 2013 14:31:47 +0100, Earl Evleth <evl...@wanadoo.fr>
>> >wrote:
>>
>> >>Police: Las Vegas Cop Killed Family, Self
>>
>> >>Las Vegas officials said a local police officer killed his family and then
>> >>set his home on fire before eventually killing himself on Monday. Police in
>> >>Boulder City, a suburb of Las Vegas, received a call at 8:20 a.m. on Monday
>> >>from a man who said he had killed his wife and son and was planning on
>> >>setting his home on fire. While they would only confirm it was an off-duty
>> >>Las Vegas officer, the house belonged to Lt. Hans Walters, 52, and his
>> >>wife, Kathryn, 46. When police responded to the call, the man at the house
>> >>had a shotgun and ignored officers warnings and entered the burning house.
>> >>The coroner confirmed three bodies were found in the house.
>>
>> >I have no problem with people who kill themselves. ? But why is it so
>> >many of these bastards want to kill other people --- before killing
>> >themselves. ? ?There's been a lot of them recently. ? ? I hope the
>> >hottest spot in hell is reserved for them.
>>
>> ? ?It's our primal state. ?Such people have cast off the veneer
>> of civilization, and it is just a veneer. ?The beast that is inside
>> all of us has come to the surface and taken over in them.
>>
>> ? ?Look what we do to cows and chickens, or fish, or whales
>> who are intelligent in an order comparable to our own,
>> without giving much thought to it. ?That's what we really are,
>> underneath the shallow mask.
>>
>> ? ?We do have to stamp out the "sociopathy" when it arises
>> from the depths of what is inside all of us, for the sake of the
>> common good of mankind, but that doesn't help the other
>> animals. ?Our behaviour toward them is what we really are.
>>
>> ? ?Here's Matt again:
>>
>> ... The Sea of Faith
>> Was once, too, at the full, and round earth's shore
>> Lay like the folds of a bright girdle furled.
>> But now I only hear
>> Its melancholy, long, withdrawing roar,
>> Retreating, to the breath
>> Of the night-wind, down the vast edges drear
>> And naked shingles of the world.
>>
>> Ah, love, let us be true
>> To one another! for the world, which seems
>> To lie before us like a land of dreams,
>> So various, so beautiful, so new,
>> Hath really neither joy, nor love, nor light,
>> Nor certitude, nor peace, nor help for pain;
>> And we are here as on a darkling plain
>> Swept with confused alarms of struggle and flight,
>> Where ignorant armies clash by night.
>>
>> ? ?-- Matthew Arnold, from "Dover Beach"http://www.victorianweb.org/authors/arnold/writings/dover...
>
>One would think that psychiatrists, by now, would have been able to
>develop fairly reliable, tricky, little tests by now to identify
>people (especially police officers) who are unstable, but I guess not.

How often? Every year? Every month? Perhaps we could all ware a meter
on our chests showing our level of stability?

People change, their mental health changes. Stress, age, physical
factors and more push people's ability to cope.

There are no guarantees where human beings are concerned. We were
never intended for long term success (my opinion) we are too
unbalanced and way to smart. No a good combination I think.

mg

1/23/2013 2:35:00 AM

0

On Jan 22, 3:24 pm, Gary <n...@none.com> wrote:
> On Tue, 22 Jan 2013 14:00:32 -0800 (PST), mg <mgkel...@yahoo.com>
> wrote:
>
> >One would think that psychiatrists, by now, would have been able to
> >develop fairly reliable, tricky, little tests by now to identify
> >people (especially police officers) who are unstable, but I guess not.
>
> Unlike intelligence and syphilis,   crazy doesn't show up well on a
> test.

I know, I know, but with the kind of money psychiatrists make, you
would think they would be able to do something useful by now.

mg

1/23/2013 2:46:00 AM

0

On Jan 22, 7:05 pm, brian <bfunk...@cox.net> wrote:
> On Tue, 22 Jan 2013 14:00:32 -0800 (PST), mg <mgkel...@yahoo.com>
> wrote:
>
>
>
>
>
>
>
>
>
> >On Jan 22, 1:20 pm, rumpelstiltskin <rumpelstilts...@x.com> wrote:
> >> On Tue, 22 Jan 2013 10:35:20 -0500, Gary <n...@none.com> wrote:
> >> >On Tue, 22 Jan 2013 14:31:47 +0100, Earl Evleth <evl...@wanadoo.fr>
> >> >wrote:
>
> >> >>Police: Las Vegas Cop Killed Family, Self
>
> >> >>Las Vegas officials said a local police officer killed his family and then
> >> >>set his home on fire before eventually killing himself on Monday. Police in
> >> >>Boulder City, a suburb of Las Vegas, received a call at 8:20 a.m. on Monday
> >> >>from a man who said he had killed his wife and son and was planning on
> >> >>setting his home on fire. While they would only confirm it was an off-duty
> >> >>Las Vegas officer, the house belonged to Lt. Hans Walters, 52, and his
> >> >>wife, Kathryn, 46. When police responded to the call, the man at the house
> >> >>had a shotgun and ignored officers warnings and entered the burning house.
> >> >>The coroner confirmed three bodies were found in the house.
>
> >> >I have no problem with people who kill themselves. But why is it so
> >> >many of these bastards want to kill other people --- before killing
> >> >themselves. There's been a lot of them recently. I hope the
> >> >hottest spot in hell is reserved for them.
>
> >> It's our primal state. Such people have cast off the veneer
> >> of civilization, and it is just a veneer. The beast that is inside
> >> all of us has come to the surface and taken over in them.
>
> >> Look what we do to cows and chickens, or fish, or whales
> >> who are intelligent in an order comparable to our own,
> >> without giving much thought to it. That's what we really are,
> >> underneath the shallow mask.
>
> >> We do have to stamp out the "sociopathy" when it arises
> >> from the depths of what is inside all of us, for the sake of the
> >> common good of mankind, but that doesn't help the other
> >> animals. Our behaviour toward them is what we really are.
>
> >> Here's Matt again:
>
> >> ... The Sea of Faith
> >> Was once, too, at the full, and round earth's shore
> >> Lay like the folds of a bright girdle furled.
> >> But now I only hear
> >> Its melancholy, long, withdrawing roar,
> >> Retreating, to the breath
> >> Of the night-wind, down the vast edges drear
> >> And naked shingles of the world.
>
> >> Ah, love, let us be true
> >> To one another! for the world, which seems
> >> To lie before us like a land of dreams,
> >> So various, so beautiful, so new,
> >> Hath really neither joy, nor love, nor light,
> >> Nor certitude, nor peace, nor help for pain;
> >> And we are here as on a darkling plain
> >> Swept with confused alarms of struggle and flight,
> >> Where ignorant armies clash by night.
>
> >> -- Matthew Arnold, from "Dover Beach"http://www.victorianweb.org/authors/arnold/writings/dover...
>
> >One would think that psychiatrists, by now, would have been able to
> >develop fairly reliable, tricky, little tests by now to identify
> >people (especially police officers) who are unstable, but I guess not.
>
> How often? Every year? Every month? Perhaps we could all ware a meter
> on our chests showing our level of stability?
>
> People change, their mental health changes. Stress, age, physical
> factors and more push people's ability to cope.
>
> There are no guarantees where human beings are concerned. We were
> never intended for long term success (my opinion) we are too
> unbalanced and way to smart. No a good combination I think.

That's all very true, but it must be a real ego deflator for the
department psychiatrist. Maybe somebody ought to send the
psychiatrists to a psychiatrist one in awhile, or give him a pay
cut. :-)