From: Holger Mack Date: 2008-09-24T05:35:23+09:00 Subject: Re: One-Liners Mashup (#177 again) ------=_Part_50467_2837073.1222202128347 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline class Array def to_s collect{|x| x.to_s.gsub(/\n/,"\n| ")}.join("\n|-- ") end end puts [:foo, [:bar, [:baz, :quux], :hello, :world], :done].to_s Works fine for given example but fails for example with puts [:a, [:b, :c]].to_s a |-- b | |-- c Still working on this... ----------------------------------------------------------------------------- New question Write a oneliner next_fib(n) which gives the smallest Fibonacci number greater than n http://en.wikipedia.org/wiki/Fibonacci_number 2008/9/22 Martin DeMello > 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 > > ------=_Part_50467_2837073.1222202128347--