euler/python/e055.py

25 lines
499 B
Python
Raw Normal View History

2019-07-18 03:29:59 +02:00
from lib_misc import is_palindrome
2019-07-18 03:29:59 +02:00
def get_digit_inverse(n):
return int(str(n)[::-1])
def is_not_lychrel(n, iterations=50):
for i in range(0, iterations):
n = n + get_digit_inverse(n)
if is_palindrome(n):
return (i + 1)
return 0
2019-07-18 03:29:59 +02:00
def euler_055():
lychrels = [n for n in range(1, 10000) if is_not_lychrel(n) == 0]
s = len(lychrels)
return s
if __name__ == "__main__":
print("e055.py: " + str(euler_055()))
2019-07-18 03:29:59 +02:00
assert(euler_055() == 249)