Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. # The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
  2. #
  3. # Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
  4. #
  5. # (Please note that the palindromic number, in either base, may not include leading zeros.)
  6.  
  7.  
  8. def is_palindrome(x):
  9. return x == x[::-1]
  10.  
  11.  
  12. N = 1000000
  13.  
  14. 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