Question: Write a function which returns the next value in the Collatz sequence. To calculate the next value in the Collatz sequence given a value n:


Write a function which returns the next value in the Collatz sequence. To calculate the next value in the Collatz sequence given a value n: If the given value n is even, the next value should be n/2 o If n is odd, the next value should be 3n+1 .Ifn is not positive the function should return 0. The Collatz conjecture states that if you repeat this process for any positive integer n the sequence will eventually reach 1. It is not known whether or not this is true. . Your function should take one integer parameter. Your function should not print anything . Your function should return the next value in the Collatz sequence. * Your function MUST be named collatzStep
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
