-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path36b.py
More file actions
51 lines (42 loc) · 1.08 KB
/
Copy path36b.py
File metadata and controls
51 lines (42 loc) · 1.08 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
result = []
def isPal(num):
strNum = str(num)
middle = int(len(strNum)/2)
first = strNum[0:middle]
if len(strNum)%2 == 0:
second = strNum[middle:]
else:
second = strNum[middle+1:]
if first == second[::-1]:
return True
else:
return False
def isBinPal(strBinNum):
middle = int(len(strBinNum)/2)
first = strBinNum[0:middle]
if len(strBinNum)%2 == 0:
second = strBinNum[middle:]
else:
second = strBinNum[middle+1:]
if first == second[::-1]:
return True
else:
return False
def main():
for x in range(1,1000001):
if isPal(x) and isBinPal(bin(x)[2:]):
print(x)
result.append(x)
summ = 0
for x in result:
summ = summ + x
print(summ)
def testIsPal():
if not isPal(3):
print("Alarm", 3)
if not isPal(585):
print("Alarm",585)
if not isBinPal('11'):
print("Alarm",'11')
if not isBinPal('10000001'):
print("Alarm",'10000001')