Home Project Euler Teaching Projects Gallery

Problem 36: Double base palindrome

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.)


Algorthim:

I didn't really find a good way of doing this problem. But, Python has a function that converts a number to binary digits. WE can just check if the binary number and the number itself is Palindromic and we have the function for checking palindrome condition. Simple.

Code:

Result:

Answer: 872187
Runtime: 43.5 seconds