From: Martin DeMello Date: 2008-09-23T06:26:34+09:00 Subject: Re: One-Liners Mashup (#177 again) 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 Followon: Given an s-expression, print it out as a tree, where [:a, :b, :c, :d] is the node with parent a and children b, c and d [:foo, [:bar, [:baz, :quux], :hello, :world], :done] #=> foo | -- bar | | -- baz | | | -- quux | | -- hello | | -- world | -- done martin