|
|
|
 |
 |
 |
|
Hailstone Sequence
|
|
|  |
by Rodney Hoffman Occidental College Los Angeles, California
 |
|
|  |
More Nifty Assignments...
Assignment
Write a method that computes a hailstone sequence (for a given seed) and calculates its length and the highest value reached.
Do the hailstone sequence for all numbers up to 1,000. Find and report the five numbers that take the most steps and the five numbers that reach the highest value.
Background
The hailstone sequence, sometimes called the 3n+1 sequence, is defined by a function f(n):
For example, here are the hailstone sequences for the numbers 7 through 9:
7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
8 4 2 1
9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
For more information about hailstone sequences, plus a suggestion for writing the calculation method, you can refer to chapter 6 of Owen Astrachan's A Computer Science Tapestry, 2nd ed. (page 272), available as a PDF.
Chapter 6 of A Computer Science Tapestry
Contribute
If you would like to contribute your suggestions for nifty assignments, please submit your ideas.
|
|
|
|
|
|