euler/ruby/euler055.rb

18 lines
293 B
Ruby
Raw Normal View History

2014-11-20 21:54:55 +00:00
require_relative 'euler'
def reverse_and_add(n)
n + Euler.from_digit_list(n.to_digit_list.reverse)
end
def lychrel_number?(n)
50.times do
n = reverse_and_add(n)
return false if Euler.palindrome?(n)
end
true
end
def solution
(1..10000).count { |x| lychrel_number?(x) }
end