Question: P#2. Sequence. Suppose we select some initial number X and then build the sequence of values by the following rules: I-1 even +1 forX- odd
P#2. Sequence. Suppose we select some initial number X and then build the sequence of values by the following rules: I-1 even +1 forX- odd If X-1 is odd, the next element in the sequence grows, and if it is even, the next element in the sequence decreases. For example, with the starting x 17 we have the sequence: 17 52 26 13 40 20 10 5 16 8421 After the sequence reaches 1 it enters the infinite loop 1 4214 21 Your task is for given numbers to calculate how many steps are necessary to come to 1. For the starting X-17, the number of steps to get to 1 is 12 (Le., one less the number of sequence elements) Starting value, Number of Steps to reach one 0 3, 10, 5, 16, 8, 4, 2,1 4, 2, 5, 16, 8,4,2, 1 6,3,10, 5, 16, 8,4, 2, Write code to compute the elements of the sequence for starting values from 1 to 50. Make a plot of the starting value versus the number of steps required to reach 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
