On Jun 15, 12:59   Ѯ
> Hi guys, I wonder if someone can find a pure ruby solution instead of
> mine (I still can get out of my *loop* mind):

You can certainly do things in a more Rubyish way, but since you're
constrained by the computational complexity, any method you use you
have to know the complexity of.  And the Ruby docs don't necessarily
tell you, forcing you to dig into the Ruby source, much of which is in
C.

For example, you use the code:

> back.unshift(mb)

That line is in a loop of n iterations.  Now *if* unshift is itself
O(n), you just went to O(n**2).  Oops!

Here's a snippet of your code:

> ans = []
> front.each_index{|k| ans.push(front[k]*back[k]) }

A more Rubyish way to do that would be:

ans = front.zip(back).map { |f, b| f * b }

But I can't be certain of the computational complexity of the call to
zip.  Now I suspect it is O(n), and if it is then you're home free.
But if not you can kiss your Google dream job goodbye. ;)

Eric

====

LearnRuby.com offers Rails & Ruby HANDS-ON public & ON-SITE
workshops.
   Ruby Fundamentals Workshop        June 16-18    Ann Arbor, Mich.
   Ready for Rails Ruby Workshop     June 23-24    Ann Arbor, Mich.
   Ruby on Rails Workshop            June 25-27    Ann Arbor, Mich.
   Ruby Plus Rails Combo Workshop    June 23-27    Ann Arbor, Mich.
Please visit http://LearnRuby.com for all the details.