Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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.)
- def is_palindrome(x):
- return x == x[::-1]
- N = 1000000
- print(sum(x for x in range(N) if is_palindrome(str(x)) and is_palindrome("{0:b}".format(x))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement