From: Harry Kakueki Date: 2013-06-01T19:18:22+09:00 Subject: Re: Eloquent Ruby Kaprekar's Number --047d7bf17d6c7e333f04de14f9ed Content-Type: text/plain; charset=ISO-8859-1 Your requirements seem to be different than the definition that I read. See Josh's solution and link. For example, you are missing 4879. Anyway, FWIW. def try1(n) s,a = n.to_s.size,[] (s...s*2).each{|y| a << (n **2)/(10**y)+(n**2)%(10**y)} a.include?(n) end arr = [] (1..100_000).each{|x|arr << x if try1(x)} p arr #> [1, 9, 45, 55, 99, 297, 703, 999, 2223, 2728, 4879, 4950, 5050, 5292, 7272, 7777, 9999, 17344, 22222, 38962, 77778, 82656, 95121, 99999] Harry --047d7bf17d6c7e333f04de14f9ed Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Your requirements seem to be different than= the definition that I read. See Josh's solution and link.
For= example, you are missing 4879.

Anyway, FWIW.


def t= ry1(n)
=A0 s,a =3D n.to_s.size,[]
=A0 (s...s*2).each{|y| a << (n **2)/(10= **y)+(n**2)%(10**y)}
=A0 a.include?(n)
end

arr =3D []
(1..1= 00_000).each{|x|arr << x if try1(x)}
p arr #> [1, 9, 45, 55, 99= , 297, 703, 999, 2223, 2728, 4879, 4950, 5050, 5292, 7272, 7777, 9999, 1734= 4, 22222, 38962, 77778, 82656, 95121, 99999]



Harry

--047d7bf17d6c7e333f04de14f9ed--