Created
March 19, 2018 18:45
-
-
Save m-zakeri/0080a7d14f74b954303de209661a8844 to your computer and use it in GitHub Desktop.
solution for problem 36 projecteuler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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