From: Tom Armitage Date: 2006-06-29T20:09:25+09:00 Subject: Re: pp Pascal (#84) Buh. Option c is so much more obvious. I was pretty much writing it as I sketched out the algorithm, rather than going for the best Ruby. Good points Simon, thanks. On 29/06/06, Simon Kr�ger wrote: > Tom Armitage schrieb: > > OK, so this isn't going to win many prizes for speed or correctness > > (my alignment sucks as the triangle gets bigger) but at least I tried. > > Second RubyQuiz entry, from a complete numpty... > > > > # Pascal's triangle - Rubyquiz # 84 > > > > rows = ARGV[0].to_i > > @output = [] > > > > puts "Pascal's triangle with #{rows} rows" > > > > count = 0 > > > > 1.upto(rows) do |i| > > if count == 0 > > [...] > > just some short remarks: > 1) you don't use i > 2) count is always i-1 > > so you may > a) remove |i| > or > b) remove count and use i-1 > or > c) change the loop to > > 0.upto(rows-1) do |count| > > and remove all 'count = count.next' lines. > (and the 'count = 0' line) > > fell free to ignore, happy coding. > > Simon > >