Skip to content

Instantly share code, notes, and snippets.

@m-zakeri
Created March 19, 2018 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-zakeri/0080a7d14f74b954303de209661a8844 to your computer and use it in GitHub Desktop.
Save m-zakeri/0080a7d14f74b954303de209661a8844 to your computer and use it in GitHub Desktop.
solution for problem 36 projecteuler
"""
https://projecteuler.net/problem=36
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.)
"""
count = 0
for i in range(1000000):
integer = str(i)
integer_reverse = integer[::-1]
binary = "{0:b}".format(i)
binary_reverse = binary[::-1]
if binary == binary_reverse and integer == integer_reverse:
count += i
print(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment