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

In [10]:
is_palindromes?(101)


Out[10]:
true

In [11]:
def is_palindromes_by_double?(n)
  n.to_s(2) == n.to_s(2).reverse
end

In [12]:
is_palindromes_by_double?(585)


Out[12]:
true

In [13]:
results = []
(1..1_000_000).each do |n|
  results << n if is_palindromes?(n) and is_palindromes_by_double?(n)
end
results


Out[13]:
[1, 3, 5, 7, 9, 33, 99, 313, 585, 717, 7447, 9009, 15351, 32223, 39993, 53235, 53835, 73737, 585585]

In [14]:
results.inject *:+


Out[14]:
872187

In [ ]: