From: Harry Kakueki Date: 2013-06-01T22:21:16+09:00 Subject: Re: Eloquent Ruby Kaprekar's Number --047d7b6d9d3029a4d804de179b01 Content-Type: text/plain; charset=ISO-8859-1 > > This should be faster than my previous solution (if it matters). > def try2(n) s, q = n.to_s.size, n*n (s...s*2).each do|x| y = 10**x return true if n == q/y+q%y end false end Harry --047d7b6d9d3029a4d804de179b01 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
=A0This should be faster than= my previous solution (if it matters).


=A0
def try2(n)
=A0 s, q =3D n.to_s.size,= n*n
=A0 (s...s*2).each do|x|
=A0=A0=A0 y =3D 10**x
=A0=A0=A0 retu= rn true if n =3D=3D q/y+q%y
=A0 end
=A0 false
end



<= /div>
Harry

--047d7b6d9d3029a4d804de179b01--