Palindromic Sum (Due 20 Feb 2016)

If any number is reversed and added to itself, and the process repeated long enough, a palindromic number will result most of the time. A palindromic number is one that reads the same forward and backward.

We will define cycle length in this scenario as the number of steps required to achieve a palindromic number. A step is defined to be the addition of the reverse of a number to itself.

The cycle length of all palindromic numbers is zero. Since all single digits numbers are palindromic, their cycle length is zero.

If the starting number is 57 then the number of steps taken to reach a palindromic number is 2.

57
132  [57 + 75 = 132]
363  [132 + 231 = 363]
The cycle length of 57 is 2.

Some numbers are particularly obtuse in attaining the palindromic state. One such number is 89. Here are the intermediate numbers before it becomes palindromic.

89
187
968
1837
9218
17347
91718
173437
907808
1716517
8872688
17735476
85189247
159487405
664272356
1317544822
3602001953
7193004016
13297007933
47267087164
93445163438
176881317877
955594506548
1801200002107
8813200023188
So the cycle length of 89 is 24. Interestingly, there are twelve numbers less than 1000 which when added repeatedly to its reverse leads to the palindrome 8813200023188. One of those numbers is a palindrome 484.

There is a natural tendency of for this set of reverse-sum operations to lead to a palindromic number. However, there are some sequences that never yield a perfect palindrome. One such sequence starts with 196. We have computed millions of terms starting with 196 and have never reached a palindrome. There is no proof that there exists any number in base 10 that leads to an infinite sequence of non-palindromic numbers.

In your program you will determine the number having the longest cycle length in a user defined range. You will prompt the user to enter the starting number of the range and the ending number. After you have read both the numbers, you will check if both numbers are positive (> 0) individually and then you will check that the starting number in the user defined range is strictly less than the ending number in that range. If the input does not meet the specifications, prompt the user to enter both the starting and ending numbers.

Once the beginning and ending of the range have been verified, your program will compute the cycle length for each of the numbers in that range inclusive of the end points. Your program will print out the number that has the largest cycle length and what that cycle length is. If there are two or more numbers that have the same largest cycle length, then print only the last number (greatest number) that has the largest cycle length.

Your sample session will look like this:

Enter starting number of the range: 80

Enter ending number of the range: 90

The number 89 has the longest cycle length of 24.

In your program you must use the functions rev_num() and is_palindromic() that we developed in class.

The program that you will be writing will be called PalindromicSum.py. We will be looking at good documentation, design, and adherence to the coding convention as discussed in class. Your file PalindromicSum.py will have the following header:

#  File: PalindromicSum.py

#  Description:

#  Student Name:

#  Student UT EID:

#  Course Name: CS 303E

#  Unique Number: 

#  Date Created:

#  Date Last Modified:

Use the Canvas program to submit your PalindromicSum.py file. We should receive your work by 11 PM on Saturday, 20 Feb 2016. There will be substantial penalties if you do not adhere to the guidelines.