Project Euler

I am completely addicted to this site…its all about solving math problems using programming.

Here is the solution to one of the problems

How Many Lychrel Numbers are below 10,000 ? http://projecteuler.net/index.php?section=problems&id=55

my solution in python, which takes abt 39 seconds:-

def lychrel(x):
 i = 0
 while i < 50:
  x += int(str(x)[::-1])
  if str(x) == str(x)[::-1]:
   return False
  i += 1
 return True

print len ([x for x in range(1,10000) if lychrel(x)])

Comments

comments powered by Disqus