How many integers 0 < n < 10E18 have the property that the sum of the digits of n equals the sum of digits of 137n?

Posted by Allen on Stack Overflow See other posts from Stack Overflow or by Allen
Published on 2010-12-26T17:30:55Z Indexed on 2010/12/26 17:54 UTC
Read the original article Hit count: 148

Filed under:
|

I'm stumped on a project Euler question, #290. Can anybody point me in the right direction?

 i = 0
 o = 0
 p = 1
 while i < 10 ** 18
   j = i.to_s.split('').map(&:to_i)
   k = j.inject(:+)

   l = 137 * i
   m = l.to_s.split('').map(&:to_i)
   n = m.inject(:+)

   if k == n
      o += 1
   end

    if i == (9 * 10 ** p) * (10 ** p)
        i += 18
        p += 1
        o += 1
    else
        i += 9
    end
 end

 puts o

© Stack Overflow or respective owner

Related posts about ruby

Related posts about project-euler