WSQ08 «I am 196»

Instrunctions

Your job is 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”.

The report must show:
  • The range of numbers analysed (lower to upper bound)
  • The number of natural palindromes (no addition to inverse needed)
  • The number of non-Lycherels encountered (become palindromes)
  • The number of Lycherel number candidates (that did not converge to palindrome)

Since you will not be able to prove that a number is Lycherel (since you cannot computer forever to check), our definition for a Lycherel candidate will be if a number does not converge after 30 iterations of applying the addition to the inverse.

Procedure

We will create a function that using a for loop and a palindrome funcion, (wich we are going to import) will determine if a number its a natural palindrome or not.

Then in the for loop we will use a while loop that will be execute 30 times, we will put two ifs in this while loop, one that will tell us if the numer after 30 iteration or less, results being palindrome and another one that will tell us if it doesn’t happen.

wsq08(2)

wsq08

Deja un comentario