40 lines
704 B
Python
40 lines
704 B
Python
#!/usr/bin/env python3
|
|
|
|
def lychrel(x):
|
|
ly=[]
|
|
i=1
|
|
while i<x:
|
|
num=i
|
|
count=0
|
|
while count<50:
|
|
num=num+analogize(digitize(num)[::-1])
|
|
if pal_check(num):
|
|
break
|
|
count+=1
|
|
else:
|
|
ly.append(i)
|
|
i+=1
|
|
return ly
|
|
|
|
def analogize(x):
|
|
i=0
|
|
num=0
|
|
while i<len(x):
|
|
num+=x[i]*(10**i)
|
|
i+=1
|
|
return num
|
|
|
|
def pal_check(x):
|
|
d=digitize(x)
|
|
if d==d[::-1]:
|
|
return True
|
|
return False
|
|
|
|
def digitize(x):
|
|
if x<10:
|
|
return [x]
|
|
return [x%10]+digitize(x//10)
|
|
|
|
if __name__ == '__main__':
|
|
print(len(lychrel(10**4)))
|