[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Creating an array with incrementing values up to a certain number

Brian Ross

8/17/2008 10:07:00 PM

[Note: parts of this message were removed to make it a legal post.]

Hello,

Another basic question, thanks for the help on the last one. I wanted to
come up with the above described program and came up with this:

# array.rb start

a = [1]
x = 0
while x < 99
a[(x+1)] = (a[x] + 1)
x = x + 1
end
p a

# array.rb end

This worked fine, but is there a more elegant way of doing this? It seems a
bit clumsy.

Brian

5 Answers

Mitchell Holman

10/20/2007 2:43:00 AM

0

Frank Pittel <fwp@warlock.deepthought.com> wrote in
news:o8-dnTJ-YPlOzoTanZ2dnUVZ_vninZ2d@giganews.com:

> In alt.politics.usa.republican Bonehead Bush <BonedBush@wh.net> wrote:
>: Here's what a REAL conservative had to say, 14 years ago, about the
>: state of the Republican party today:
>
>: "The conservative movement is founded on the simple tenet that people
>: have the right to live life as they please, as long as they don't hurt
>: anyone else in the process."
>
>: "The radical right has nearly ruined our party."
>
>: - Barry Goldwater, 1994
>
>: How soon they forgot.............
>
> How soon you looney tune brain dead lying loser lib dems hated Barry
> Godwater and felt free to spread the most dispicable lies about him.


Actually Goldwater was probably the last honest
Republican. He really believed in smaller government,
fiscal restraint, and personal freedom. Which is why
the neo-cons shoved him out of the party for not
signing on with their Religious Right morality that
dictated what everyone should believe, borrow-and-spend,
government-as-Big-Brother attitude.


Mitchell Holman

"I think every good Christian ought to kick Falwell
right in the ass."
Barry Goldwater


George Grapman

10/20/2007 2:52:00 AM

0

Mitchell Holman wrote:
> Frank Pittel <fwp@warlock.deepthought.com> wrote in
> news:o8-dnTJ-YPlOzoTanZ2dnUVZ_vninZ2d@giganews.com:
>
>> In alt.politics.usa.republican Bonehead Bush <BonedBush@wh.net> wrote:
>> : Here's what a REAL conservative had to say, 14 years ago, about the
>> : state of the Republican party today:
>>
>> : "The conservative movement is founded on the simple tenet that people
>> : have the right to live life as they please, as long as they don't hurt
>> : anyone else in the process."
>>
>> : "The radical right has nearly ruined our party."
>>
>> : - Barry Goldwater, 1994
>>
>> : How soon they forgot.............
>>
>> How soon you looney tune brain dead lying loser lib dems hated Barry
>> Godwater and felt free to spread the most dispicable lies about him.
>
>
> Actually Goldwater was probably the last honest
> Republican. He really believed in smaller government,
> fiscal restraint, and personal freedom. Which is why
> the neo-cons shoved him out of the party for not
> signing on with their Religious Right morality that
> dictated what everyone should believe, borrow-and-spend,
> government-as-Big-Brother attitude.
>
>
> Mitchell Holman
>
> "I think every good Christian ought to kick Falwell
> right in the ass."
> Barry Goldwater
>
>
I remember reading an interview with Goldwater shortly before his
death. His comments on some people (not verbatim)

Falwell-a crackpot.
Gingrich- talks too much
Limbaugh- I have better things to do with my time.

Farrel Lifson

8/17/2008 10:22:00 PM

0

irb(main):004:0> i = 0
=> 0
irb(main):005:0> a = Array.new(99){i+=1}
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]

Farrel
--
Aimred - Ruby Development and Consulting
http://www....

Rick DeNatale

8/17/2008 10:22:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Sun, Aug 17, 2008 at 6:07 PM, Brian Ross <p.brian.ross@gmail.com> wrote:

> Hello,
>
> Another basic question, thanks for the help on the last one. I wanted to
> come up with the above described program and came up with this:
>
> # array.rb start
>
> a = [1]
> x = 0
> while x < 99
> a[(x+1)] = (a[x] + 1)
> x = x + 1
> end
> p a
>
> # array.rb end
>
> This worked fine, but is there a more elegant way of doing this? It seems a
> bit clumsy.
>
>
p (1..100).to_a
--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

David A. Black

8/17/2008 10:25:00 PM

0

Hi --

On Mon, 18 Aug 2008, Brian Ross wrote:

> Hello,
>
> Another basic question, thanks for the help on the last one. I wanted to
> come up with the above described program and came up with this:
>
> # array.rb start
>
> a = [1]
> x = 0
> while x < 99
> a[(x+1)] = (a[x] + 1)
> x = x + 1
> end
> p a
>
> # array.rb end
>
> This worked fine, but is there a more elegant way of doing this? It seems a
> bit clumsy.

In addition to the other answers:

a = [*1..99]


David

--
Rails training from David A. Black and Ruby Power and Light:
Advancing With Rails August 18-21 Edison, NJ *
* Co-taught by D.A. Black and Erik Kastner
See http://www.r... for details and updates!