143k views
0 votes
PLEASE HELP! THIS IS FROM A BEGINNERS COMPUTER SCIENCE CLASS:

Write a program that generates the "Hailstone series" for any number from 1 to 1000. The Hailstone series is an interesting sequence of numbers, and can be calculated like this:

If the current value of n is even, the next number in the sequence will be n/2 (use integer division)
If the current value of n is odd, the next number in the sequence will be 3*n + 1
This process is repeated until you reach a value of 1. It is theorized that every integer will eventually end at 1. At the time of writing, this has been tested to be true for numbers up to ~1048, but it has never been proven!

Your program should print the Hailstone series for a particular number and the number of steps it took to reach 1.

1 Answer

3 votes

Answer:

This is an iterative approach to the problem; you could also have done a recursive approach. This version is easier to think about in my opinion.

PLEASE HELP! THIS IS FROM A BEGINNERS COMPUTER SCIENCE CLASS: Write a program that-example-1
User Cody Bonney
by
3.3k points