Skip to content

Instantly share code, notes, and snippets.

@gilrg18
Created April 10, 2015 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilrg18/bab0662f9fbb08f4410e to your computer and use it in GitHub Desktop.
Save gilrg18/bab0662f9fbb08f4410e to your computer and use it in GitHub Desktop.
WSQ11
#Gilberto Rogel García A01630171 YOSOY196
def palindromes(x):
x1 = str(x)
x2 = x1[::-1]
x3 = int(x2)
if(x==x3):
return True
else:
return False
npalindromes = 0
nonlychrels = 0
Lychrels = 0
x = int(input("Give me the lower bound of numbers to consider: "))
y = int(input("Give me the upper bound of numbers to consider: "))
print("And the results are for the range",x, "to",y)
for c in range(x,y+1):
c1 = palindromes(c)
if(c1==False):
c2 = 0
p1 = False
candidate = c
while(c2<30 and p1==False):
c2 = c2 + 1
c3 = str(candidate)
r = c3[::-1]
r1 = int(r)
candidate += + r1
p1 = palindromes(candidate)
if(p1==True):
nonlychrels += + 1
if(c2==30 and p1==False):
Lychrels += + 1
else:
npalindromes += + 1
print("Natural Palindromes: ", npalindromes)
print("Non Lychrel (become palindrome): ", nonlychrels)
print("Lychrel candidates : ", Lychrels)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment