Project Euler Problem 036


The decimal number, $585 = 1001001001_2$ (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.)


This solution is quite straight-forward just notice the detail that I compare just non numbers.
This is because no even number will be palindromic in their binary representation due to the
fact that they end in 0 and there is no 0 in the beginning.

from CommonFunctions import is_palindrome
if __name__ == '__main__':
    result = sum(x for x in range(1, 1000000, 2) if is_palindrome(x) and is_palindrome(bin(x)[2:]))
    print("The result is:", result)

The Python file is available for download here.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License