-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path55.py
More file actions
executable file
·39 lines (33 loc) · 891 Bytes
/
55.py
File metadata and controls
executable file
·39 lines (33 loc) · 891 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
29
30
31
32
33
34
35
36
37
38
39
def check_palindrome(input, case=True, strip=True):
bar = ascii(input)
if strip:
bar = bar.replace(' ', '')
if case:
bar = bar.upper()
length = len(bar)
if length % 2 == 0:
if (bar[:(length // 2)]) == (bar[length:(length // 2 - 1):-1]):
return True
else:
if (bar[:(length // 2)]) == (bar[length:(length // 2):-1]):
return True
return False
def IsLychrel(x, r=0):
if r >= 50:
return True
print('Recursed', r, 'times')
print('Starting with', x)
print('Adding', str(x)[::-1])
x += int(str(x)[::-1])
print('To get', x)
if not check_palindrome(str(x)):
print('Is not a palindrome')
return IsLychrel(x, r + 1)
else:
print('Is Palindromic')
return False
num = 0
for i in range(1, 10001):
if IsLychrel(i):
num += 1
print(num)