|
You should solve the problem and write your code in ONE python file. When you are done, you SHOULD COMPRESS the file into one zip file and SUBMIT THE COMPRESSED FILE ONLY (for example, Assignment1.zip). Submission should be made ONLINE through the PORTAL. NO OTHER FORM OF SUBMISSION will be accepted. Therefore, if you do not submit online through the portal, you will get ZERO for this assignment. Problem: A CONJECTURE [100 Marks] Consider the following algorithm: 1. input n 2. print n 3. while n ~= 1 4. if n is odd then n = 3n+1 5. else n = n/2 Given the input 22, the following sequence of numbers will be printed by the above algorithm: 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that 0 < n < 1,000,000 (and, in fact, for many more numbers than this.) Given an input n, it is possible to determine the number of numbers printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16. For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j (inclusive). INPUT SPECIFICATION The input will consist of a series of pairs of integers i and j (i may be greater than j and vice-versa). All integers will be less than 1,000,000 and greater than 0. You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j. OUTPUT SPECIFICATION For each pair of input integers i and j you should output the maximum cycle length for integers between and including i and j. The string to print is as follows: The Maximum Cycle Length is: SAMPLE INPUT and OUTPUT Case 1: Please Enter the Value for i: 1 Please Enter the Value for j: 10 The Maximum Cycle Length is: 20 Case 2: Please Enter the Value for i: 100 Please Enter the Value for j: 200 The Maximum Cycle Length is: 125 Case 3: Please Enter the Value for i: 201 Please Enter the Value for j: 210 The Maximum Cycle Length is: 89 Case 4: Please Enter the Value for i: 900 Please Enter the Value for j: 1000 The Maximum Cycle Length is: 174 ACKNOWLEDGEMENTS The original version of this assignment was set as a programming challenge on ACM (http://acm.uva.es/p/v1/100.html). This is slightly modified in the sense that in the original problem you have to read from files and you have a time limit within which you should produce your output.
|