Question: Write code for a RACKET function that recursively applies the Collatz Function to an input positive integer. The Collatz function is defined by f(x) =
Write code for a RACKET function that recursively applies the Collatz Function to an input positive integer. The Collatz function is defined by f(x) = x/2 when x is even and f(x) = 3x + 1 when x is odd. It is known that for any input of a positive integer for x, the recursion will eventually reach 1. You can read more about this function on Wikipedia. You are to write code for a Racket function that recursively applies the Collatz Function to the input positive integer. Your output is the number of iterations until the value of 1 is attained. The function that kicks off the processed should be invoked like this (collatz n) where n is the positive integer. The output is m where m is the number of iterations to attain a value of 1.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
