Created
October 31, 2010 18:37
-
-
Save PJensen/656962 to your computer and use it in GitHub Desktop.
Find the number of lychrel numbers below 10k.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
??? in 0.431851148605 seconds