From: Harry Kakueki Date: 2013-05-16T22:49:00+09:00 Subject: Re: n00b looking to learn from the best --047d7b6dbe16dccee004dcd620b3 Content-Type: text/plain; charset=ISO-8859-1 # Try this or that. def try_this(n) Array.new(n.size){|i| n[i]*i}.inject{|a,b| a+b} end def try_that(n) t = 0 (0...n.size).each{|x| t+=n[x]*x} t end n = [1,2,3,4,5] p try_this(n) p try_that(n) Harry --047d7b6dbe16dccee004dcd620b3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
# Tr= y this or that.

def try_this(n)
=A0 Array.new(n.size){|i| n[i]*i}= .inject{|a,b| a+b}
end

def try_that(n)
=A0 t =3D 0
=A0 (0..= .n.size).each{|x| t+=3Dn[x]*x}
=A0 t
end

n =3D [1,2,3,4,5]
p try_this(n)
p try_that(n)
=

Harry

--047d7b6dbe16dccee004dcd620b3--