-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pb55.py
54 lines (36 loc) · 808 Bytes
/
Pb55.py
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
52
53
54
def test_palindrome(n):
l=str(n)
i=0
j=len(l)-1
bool=True
while (i<j and bool):
if l[i] != l[j]:
bool=False
i+=1
j-=1
return bool
#print(test_palindrome(15851))
def reverse(n):
l1=str(n)
l2=""
for i in range(len(l1)-1,-1,-1):
l2+=l1[i]
return int(l2)
# print (reverse(1984))
def test_lychrel(n,num_iteration):
N=n+reverse(n)
#print(N)
if test_palindrome(N):
return False
elif num_iteration>50:
return True
else:
return test_lychrel(N,num_iteration+1)
#print(test_lychrel(349,1))
def compte_lych(n):
somme=0
for i in range(n):
if test_lychrel(i,1):
somme+=1
return somme
# print(compte_lych(10000))