Skip to content

Instantly share code, notes, and snippets.

@PJensen
Created October 31, 2010 18:37
Show Gist options
  • Save PJensen/656962 to your computer and use it in GitHub Desktop.
Save PJensen/656962 to your computer and use it in GitHub Desktop.
Find the number of lychrel numbers below 10k.
import time
##
# @File: p55.py
# @Author: PJensen
# @Version: Oct 31, 2010
# @Description: Find the number of lychrel numbers below 10k.
# http://projecteuler.net/index.php?section=problems&id=55
##
def fast_lychrel(n):
N_MAX = 50
tmp = 0; c = n
for index in range(1, N_MAX + 1):
tmp = int(c) + int(str(c)[::-1])
if (str(tmp) == (str(tmp)[::-1])):
return 0
c = tmp
return 1
tStart = time.time()
# display answer and execution time
print ('%s in %s seconds') % \
(sum([fast_lychrel(x) for x in range(0, 10000)]), \
time.time() - tStart)
@PJensen
Copy link
Author

PJensen commented Oct 31, 2010

??? in 0.431851148605 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment