Skip to content

Commit 9ed60ba

Browse files
Solution to Problem 36
1 parent 53d9989 commit 9ed60ba

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Project Euler/Problem 36/sol1.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from __future__ import print_function
2+
'''
3+
Double-base palindromes
4+
Problem 36
5+
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
6+
7+
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
8+
9+
(Please note that the palindromic number, in either base, may not include leading zeros.)
10+
'''
11+
try:
12+
xrange #Python 2
13+
except NameError:
14+
xrange = range #Python 3
15+
16+
def is_palindrome(n):
17+
n = str(n)
18+
19+
if n == n[::-1]:
20+
return True
21+
else:
22+
return False
23+
24+
total = 0
25+
26+
for i in xrange(1, 1000000):
27+
if is_palindrome(i) and is_palindrome(bin(i).split('b')[1]):
28+
total += i
29+
30+
print(total)

0 commit comments

Comments
 (0)