WSQ11 – Yo soy 196

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
Then it check the values from the lower bound (inclusive) to the upper bound (inclusive) and make a report of them. During the analysis of each number, if a Lychrel number is found it should be reported immediately with something like “Found a Lychrel number: 196”
Here is a link to the code in Github.
Python/WSQ-11(Palindromes)
This one is the most difficult of the WSQ and i had a lot of problems iterating them and comparing them.

WSQ 11 – Yo Soy 196

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:

WSQ11 – Yo soy 196

depresion-644x362

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.

WSQ11 - YoSoy196 (1)WSQ11 - YoSoy196 (2)

Link GitHub: WSQ11 – Yo Soy 196

 

Yo Soy 196

Captura de pantalla 2016-04-07 a las 15.34.05Captura de pantalla 2016-04-07 a las 15.34.35Captura de pantalla 2016-04-07 a las 15.35.15

We needed 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
Then you check the values from the lower bound (inclusive) to the upper bound (inclusive) and make a report of them. During the analysis of each number, if a Lychrel number is found it should be reported immediately with something like “Found a Lychrel number: 196”
One of my friends, Lalo Maciel, helped with this assignment so here it is.
This page helped also. https://mattmccutchen.net/bigint/

Here’s my code in GitHub.

(WSQ11) Yo soy 196

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.

wsq1101

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:

wsq1102

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:wsq1103.png

yosoy196image

Last lines are written to print the results.

wsq1103

 

Yo soy 196

This program asks the user for two pieces of data:

  • The lower bound of the sequence
  • The upper bound of the sequence
Then you check the values from the lower bound (inclusive) to the upper bound (inclusive) and make a report of them. During the analysis of each number, if a Lychrel number is found it should be reported immediately with something like “Found a Lychrel number: 196”

WSQ11

WSQ11-2

Yo soy 196. Palindromes and Lychrel numbers

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”