Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 16, 2011 18:53
Show Gist options
  • Select an option

  • Save jakedobkin/1487384 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1487384 to your computer and use it in GitHub Desktop.
Euler 55: Lychrel numbers
# http://projecteuler.net/problem=56
# first, a few functions we'll use- i particularly like the reverse
def reverse(string):
string = string[::-1]
return string
def is_pali(string):
if string==reverse(string):
return True
else:
return False
# is_lychrel is a recursive function! i wrote it without any help!
def is_lychrel(x,y):
sum = x + int(reverse(str(x)))
if is_pali(str(sum)) == True:
return False
if y > 50:
return True
else:
y = y + 1
return is_lychrel(sum,y)
# now we simply ask if each number is lychrel and count
count = 0
for i in range (0,10000):
if is_lychrel(i,0):
count += 1
print "Answer:",count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment