Question: done in python please One of the easiest to formulate, yet unsolved, problems in number theory is the Collatz Conjecture, sometimes called the Hailstone Problem.

done in python please

done in python please One of the easiest to formulate, yet unsolved,problems in number theory is the Collatz Conjecture, sometimes called the "Hailstone

One of the easiest to formulate, yet unsolved, problems in number theory is the Collatz Conjecture, sometimes called the "Hailstone Problem." Given a starting integer n,n>=1, we iterate the following sequence: - n(n/2) if n is even - n(3n+1) if n is odd The Collatz Conjecture is that for any n, this iterative sequence will end in 1 after a finite number of steps. This conjecture has defied all attempts at proof. Write a script, single.py, to implement the iterative sequence above for an integer n read from the keyboard. The iterative sequence should be printed to the screen, stop when 1 is reached, and print the number of iterations needed to reach one, i.e. C(n). Submit as the file LastnameFirstname_Lab2_single.py Part 2 Write another script, multiple.py, to compute C(n) for all integers up to one million. In this case, it is probably not wise (except when you are checking your routine) to print the sequence for each n. Your script should determine the integer which had the maximum number of iterations to reach 1 and should produce a (nice looking) plot of C(n) versus log10(n). (Check: what is the default base for logarithms in numpy?) Save the figure to a file and submit as LastnameFirstname_Lab2_Fig1.png. Submit the code as the file LastnameFirstname_Lab2_multiple.py The code that makes the plot should be included in the LastnameFirstname_Lab2_multiple.py file. Finally, time how long your script takes to finish. Hint: one simple method is the Python time module. You can use the command starttime = time.time () endtime = time.time() elapsed = endtime-starttime Part 3 Potential Speedup: As (3n+1) must be even for any odd n, the two rules can be combined into one in this case: any odd n should iterate to (3n+ 1)/2. Create a new script multiple2.py that implements this modification. Be sure to count the (3n+1)/2 step as two iterations in order to reproduce your previous results. How much faster is your new routine? The code that computes this speed-up factor should be included in the multiple2.py file. Submit as the file LastnameFirstname_Lab2_multiple2.py

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!