In [1]:
def is_palindromes?(n)
n.to_s == n.to_s.reverse
end
In [2]:
is_palindromes?(101)
Out[2]:
In [16]:
def is_palindromes_by_double?(n)
n.to_s(2) == n.to_s(2).reverse
end
In [17]:
is_palindromes_by_double?(585)
Out[17]:
In [18]:
results = []
(1..1_000_000).each do |n|
results << n if is_palindromes?(n) and is_palindromes_by_double?(n)
end
results
Out[18]:
In [19]:
results.inject *:+
Out[19]:
In [ ]: