In [1]:
def is_palindromes?(n)
  n.to_s == n.to_s.reverse
end

In [2]:
is_palindromes?(101)


Out[2]:
true

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]:
true

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]:
[1, 3, 5, 7, 9, 33, 99, 313, 585, 717, 7447, 9009, 15351, 32223, 39993, 53235, 53835, 73737, 585585]

In [19]:
results.inject *:+


Out[19]:
872187

In [ ]: