-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP036.py
More file actions
28 lines (22 loc) · 722 Bytes
/
P036.py
File metadata and controls
28 lines (22 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- coding: utf-8 -*-
#==============================================================================
# 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 isPalin(string):
return string[::-1]==string
PalinSum = 0
for ii in xrange(1000001):
if isPalin(str(ii)):
# print ii
if isPalin(bin(ii)[2:]):
# print 'winner', ii
PalinSum += ii
print PalinSum
# 872187