Hailstone Problem
Hailstone Problem
Eligiblity:
Those who have completed beginner CORE level Java Programming courses in their curriculum
Task 1:
In the philosophical excursion on the topics of holism and reductionism, the bookreader referred to
Douglas Hofstadter’s Pulitzer-prize-winning book Gödel, Escher, Bach. Hofstadter’s book contains
many interesting mathematical puzzles, many of which can be expressed in the form of computer
programs. In Chapter XII, Hofstadter mentions a wonderful problem that is well within the scope of
the control statements from JAVA.
On page 401 of the Vintage edition, Hofstadter illustrates this process with the following example,
starting with the number 15:
As you can see from this example, the numbers go up and down, but eventually—at least for all
numbers that have ever been tried—comes down to end in 1. In some respects, this process is
reminiscent of the formation of hailstones, which get carried upward by the winds over and over
again before they finally descend to the ground. Because of this analogy, this sequence of numbers
is usually called the Hailstone sequence, although it goes by many other names as well. Write a
ConsoleProgram that reads in a number from the user and then displays the Hailstone sequence for
that number, just as in Hofstadter’s book, followed by a line showing the number of steps taken to
reach 1. For example, your program should be able to produce a sample run that looks like this:
The fascinating thing about this problem is that no one has yet been able to prove that it always
stops. The number of steps in the process can certainly get very large. How many steps, for example,
does your program take when n is 27?
https://www.youtube.com/watch?v=JvYk_Aq-IME