From: Mathieu Bouchard Date: 2005-03-27T11:12:55+09:00 Subject: Re: Convert a Hash into an Array On Fri, 18 Mar 2005, Phrogz wrote: > Aside - whatever the name, what an excellent, versatile function! For > example, the linked-to geometric series sum at > http://www.brpreiss.com/books/opus8/programs/pgm02_06.txt can be > written in a more terse and (IMO) more ruby-esque way as simply: > def geometric_series_sum( x, n ) > (0..n).inject(0){ |sum,i| sum+x**i } > end And even shorter, def geometric_series_sum(x,n) (x**(n+1)-1)/(x-1) end _____________________________________________________________________ Mathieu Bouchard -=- Montr�al QC Canada -=- http://artengine.ca/matju