Question: python code The Collatz conjecture is an example of a simple computational process whose behavior is so unpredictable that the world's best mathematicians still don't

python code

The Collatz conjecture is an example of a simple computational process whose behavior is so unpredictable that the world's best mathematicians still don't understand it.

Consider the simple function f(n) (as defined in the Wikipedia page above) that takes an integer n and divides it by two if n is even and multiplies n by 3 and then adds one to the result if n is odd. The conjecture involves studying the value of expressions of the form f(f(f(...f(f(n))))) as the number of calls to the function f increases. The conjecture is that, for any non-negative integer n, repeated application of f to n yields a sequence of integers that always includes 1.

Your task for this question is to implement the Collatz function f in Python. The key to your implementation is to build a test that determines whether n is even or odd by checking whether the remainder when n is divided by 22 is either zero or one. Hint: You can compute this remainder in Python using the remainder Operator % via the expression % n % 2. Note you will also need to use integer division // when computing f.

Once you have implemented f, test the your implementation on the expression f(f(f(f(f(f(f(674))))))). This expression should evaluate to 190. Finally, compute the value of the expression f(f(f(f(f(f(f(f(f(f(f(f(f(f(1071)))))))))))))) and enter the result below as an integer. Remember to use copy and paste when moving the expressions above into your Python environment. Never try to retype expressions by hand.

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!