Problem 036


Project Euler

Double-base palindromes

Problem 36

The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.

Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.

(Please note that the palindromic number, in either base, may not include leading zeros.)


First, select only palindromic in decimal number to check by using the following method. Pick i, j, k where 1<= i <= 9, and 0 <= j,k <= 9. Create the following numbers when looping through each value.
  • i
  • ii
  • iji
  • ijji
  • ijkji
  • ijkkji

Now create a function that convert these number into binary and then create another function to check if the binary number is a palindrome. The remaining problem is to add all the results up. Since each value of i, j, k and position are unique, there will not be any repeat representation of a solution.

Advertisements