Question: I am having problems solving this: (C++ Program-recusion) The hailstones use 1859 and 119570. Print the number of iterations needed to reach the base case.

I am having problems solving this: (C++ Program-recusion)

The hailstones use 1859 and 119570. Print the number of iterations needed to reach the base case. Algorithm given below: Douglas Hofstadter's Pulitzer-prize-winning book, Gdel, Escher, Bach, poses the following mathematical puzzle:

Pick a positive integer n as the start.

If n is even, divide it by 2.

If n is odd, multiply it by 3 and add 1.

Continue this process until n is 1.

The number n will travel up and down but eventually end at 1 (at least for all numbers that have ever been tried -- nobody has ever proved that the sequence will terminate). Analogously, hailstone travels up and down in the atmosphere before eventually landing on earth. The sequence of values of n is often called a Hailstone sequence, because hailstones also travel up and down in the atmosphere before falling to earth

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