Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions