In this WSQ we need to create a program that asks the user for two pieces of data:
- The lower bound of the sequence
- The upper bound of the sequence
Fundamentals and Solutions. Together!
In this WSQ we need to create a program that asks the user for two pieces of data:
En este ejercicio lo primero que hice fue preguntarla al usuario dos numero, el primero para saber donde empieza la lista y el segundo para saber donde termina:
numero1= int(input("En que numero comienza la lista: "))
numero2= int(input("En que numero termina la lista: "))
lista=list(range(numero1,numero2+1))
Con la lista creada, use un ciclo “for” para revisar cada uno de los números en la lista. Lo que se le va a hacer a cada numero es:
Voltear sus dígitos:
inverso_n=int(str(n)[::-1])
Sumas el numero original y el mismo pero con sus dígitos al revés:
suma=inverso_n+n
Voltear los dígitos del resultado de la suma de lo anterior:
inverso_checa=int(str(suma)[::-1])
Ahora con las condiciones se haría el proceso para checar cada uno de los numero y decir su propiedad:
for n in lista:
inverso_n=int(str(n)[::-1])
suma=inverso_n+n
inverso_checa=int(str(suma)[::-1])
if n==inverso_n:
print(n,"es palindromo")
elif(suma==inverso_checa):
print(n,"No es un numero Lychrel")
else:
print(n,"Es un numero Lychrel")
Código completo:
numero1= int(input("En que numero comienza la lista: "))
numero2= int(input("En que numero termina la lista: "))
lista=list(range(numero1,numero2+1))
for n in lista:
inverso_n=int(str(n)[::-1])
suma=inverso_n+n
inverso_checa=int(str(suma)[::-1])
if n==inverso_n:
print(n,"es palindromo")
elif(suma==inverso_checa):
print(n,"No es un numero Lychrel")
else:
print(n,"Es un numero Lychrel")
Click en la imagen para ver el codigo en github:
Compilado:
Con bastante diferencia, el trabajo mas complicado que he hecho durante este curso y el mas largo. Anteriormente fue publicado en el quiz 5 palindromos, la diferencia entre ese quiz y este trabajo, es que en el quiz se usaban palindromos con letras, y en este trabajo se usan puros números.
Se tuvo que descargar una biblioteca nueva : BigInteger.
Ocupé ayuda de bastantes compañeros porque si fue un trabajo sumamente complicado.
Link GitHub: WSQ11 – Yo Soy 196
We needed to create a program that asks the user for two pieces of data:
Here’s my code in GitHub.
After a brain-burning-process, I finally got it. After some appointments to Ken’s office and tons of coffee, Yo soy 196 is here.
First of all, we shall create functions that will help us to find which number is a palindrome, which one can become one and which one is a Lycherel number.
The second part is a BIG piece of code. Here it is:
From line 13 to line 21 I created three lists to add the values depending on it’s category. And of course, I wrote the inputs to get our upper and lower bound to evaluate the range between them.
And trust me, there´s no better way to explain the following lines than with a flowchart, a magical flowchart:
Last lines are written to print the results.
This program asks the user for two pieces of data:
1.- Como primer paso hice dos funciones, una que invierta los números y otra que haga lo de ver si es palindromo natural o no lychrel ó 196.(candidato :3)
Pedi los dos numeros del limite. y, para cada caso (a<b) (b>a) o lo demás. (Que vaya imprimiendo numero por numero y le aplique a ese numero ,x, y haga la funcion de palindromo.
LINK en GITHUB
ANITA LAVA LA TINA
RECONOCER
RACE CAR
Here you can take a look at My code on GitHub.
You should really check out Orlando´s Blog post. You´ll learn how to do it perfectly.
First of all, I really have to thank Orlando Lara. Thank you for your time doing those amazing videos teaching us mortals about #WSQ11. Also many thanks to my teacher Ken Bauer, for his video explaining how to use BigInteger s on the program. You should really check out Ken´s video, cause it is kind of complex how to use and compile programs with this BigIntegers.
Basically those were all my sources to make this program. I once again thank Orlando, for teaching us how to use strings and bool functions. Before this program, I had never used them.
Following Orlando´s guide (sorry for saying it so much, but is the truth), I made my program to work with only two functions. One flips out each number of the sequence, using this:
BigInteger Num_reverse (BigInteger i){
string neto = bigIntegerToString(i);
neto = string(neto.rbegin(),neto.rend());
i = stringToBigInteger(neto);
return i;
}
It is a command to flip out the string, but what the function does first is convert once again the number from BigInteger to string (which we had already done the inverse process). Then it reverses the string and converts it back to a BigInteger using “stringToBigInteger()”.
So this function is called inside the main, on a for loop that runs from the lower bound of the sequence provided by the user to the highest. SO IT FLIPS EACH AND EVERY NUMBER OF THE SEQUENCE. After this, with an if, it checks out if the flipped number is equal to the original number. If this is true, the we just found
Continue reading “Yo soy 196. Palindromes and Lychrel numbers”