585 = 1001001001 (binary) is the number of palindromes in both decimal and binary.
Find the sum of the numbers that are less than one million and are palindromic in both decimal and binary.
(Note: It is not allowed to palindrome with 0 at the beginning.) http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2036
I manipulated the character string. I'm reflecting on it now.
def main():
MAX = 10**6
ans = 0
for i in range(MAX):
s10, s2 = str(i), str(format(i,'b'))
if s10 == s10[::-1] and s2 == s2[::-1]:
ans += i
print ans
Recommended Posts