From: Robert Dober Date: 2008-06-16T03:48:25+09:00 Subject: Re: little problem (google hiring puzzle) On Sun, Jun 15, 2008 at 6:59 PM, ex wrote: vals = ARGV.map{|x| Integer x} class Array def accumulate init, op # something like this will be in 1.9 :) inject([init]){ |a,e| a << a.last.send( op, e ) } end end ans = vals[0..-2].accumulate(1, :*). zip( vals[1..-1].reverse.accumulate(1, :*).reverse ). map{|x,y| x * y } p vals p ans I feel that one can rely on map, reverse, zip and inject to be O(N) anyway nobody asked you for O(N) performance IIRC. -- http://ruby-smalltalk.blogspot.com/ --- As simple as possible, but not simpler. Albert Einstein