Created
April 10, 2015 04:26
-
-
Save gilrg18/bab0662f9fbb08f4410e to your computer and use it in GitHub Desktop.
WSQ11
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
#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