18 lines
293 B
Ruby
18 lines
293 B
Ruby
|
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
|