036 Double-base palindromes.sf 340 B

123456789101112131415161718192021
  1. #!/usr/bin/ruby
  2. # Daniel "Trizen" Șuteu
  3. # https://github.com/trizen
  4. # Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
  5. # https://projecteuler.net/problem=36
  6. # Runtime: 3.153s
  7. var sum = 0
  8. 1e6.times {|n|
  9. if (n.is_palindrome && n.is_palindrome(2)) {
  10. sum += n
  11. }
  12. }
  13. say sum