From: Eduard Llull Date: 2008-09-23T06:36:59+09:00 Subject: Re: One-Liners Mashup (#177 again) On Monday 22 September 2008 23:26:34 Martin DeMello wrote: > On Mon, Sep 22, 2008 at 2:07 PM, Matthew Moss wrote: > > Too many solvers not providing additional problems! > > > > Here's another... Assuming you have an array of numeric data, write a > > method that returns an array of progressive sums. That is: > > > > prog_sum( [1, 5, 13, -6, 20] ) => [1, 6, 19, 13, 33] > > def prog_sum(ary) > ary.inject([0, []]) {|(s, a), i| [s+i, a<<(s+i)]}.last > end And what about def prog_sum(array) sum = 0; array.collect { |e| sum+=e } end