In [1]:
def is_palindrome(s):
s = str(s)
L = len(s)
for i in range(L/2):
if s[i] != s[-(i+1)]:
return False
return True
assert is_palindrome('racecar')
assert is_palindrome('12321')
assert is_palindrome(12321)
def make_palindrome(n):
s = str(n)
L = len(s)
for i in range(1,len(s)):
s += s[L-i-1]
return int(s)
assert make_palindrome(123) == 12321
def to_bin(n):
return bin(n)[2:]
assert to_bin(123) == '1111011'
In [2]:
double_base_palindromes = []
for n in range(10**6):
if not is_palindrome(n):
continue
pb = to_bin(n)
if is_palindrome(pb):
print n,pb
double_base_palindromes.append(n)
print sum(double_base_palindromes)
In [ ]: