Question: 2 Functions and control flows: 3n+1 problem - (6 points) Build a function that generates the following sequence of numbers. Start with any positive integer

 2 Functions and control flows: 3n+1 problem - (6 points) Build
a function that generates the following sequence of numbers. Start with any

2 Functions and control flows: 3n+1 problem - (6 points) Build a function that generates the following sequence of numbers. Start with any positive integer n, then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half of the previous one. If the previous term is odd, the next term is 3 times the previous term plus 1. The function stops when the sequence reaches 1. Note that the sequence will eventually reach 1. This is called Collatz conjecture (also called 3n+1 problem https:llwww.youtube.comlwatch?v=094y1ZprJg, httpszllen.wikipedia.org/wikilCoIlatz_conjecture), and the conjecture is that. no matter what value of n. the sequence will always reach 1. - (2 points) Run your function 3 times setting 7, 10. and 15, as start points

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 Mathematics Questions!