Created
March 2, 2017 16:55
-
-
Save hector117/5c38c115a9e8fbf855da351f356b4cde to your computer and use it in GitHub Desktop.
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
def is_palindrome(x): | |
# return true if x is a palindrome | |
rev = int(str(x)[::-1]) | |
return x == rev | |
def apply196(x): | |
rev = int(str(x)[::-1]) | |
return x + rev | |
def lychrel(low,high): | |
num_palindromes = 0 | |
non_lychrels = 0 | |
lychrels = 0 | |
for x in range(low,high+1): | |
if is_palindrome(x): | |
num_palindromes = num_palindromes + 1 | |
else: | |
# non-lycherel or lycherel | |
# repeat max 30 times, apply196 until palindrome or give up | |
copia = x | |
veces = 0 | |
while veces <= 30 and not is_palindrome(copia): | |
copia = apply196(copia) | |
veces = veces + 1 | |
if veces > 30: | |
lychrels = lychrels + 1 | |
print("WOOOHOOO, lychrel es:",x) | |
else: | |
non_lychrels = non_lychrels + 1 | |
print("Existen" ,num_palindromes,"números palíndromos naturales en tu serie") | |
print("Existen" ,non_lychrels,"números palíndromos en tu serie") | |
print("Existen" ,lychrels,"candidatos a números de Lychrel en tu serie") | |
#main program below | |
print("WSQ-08") | |
print("Ingresa el número menor de tu rango de datos") | |
x = int(input()) | |
print("Ingresa el número mayor de tu rango de datos") | |
y = int(input()) | |
lychrel(x,y) | |
print("Se analizaron todos los enteros de ",x,"a ",y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment