

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Algorithmic Problem Solving; Subject: Computer Science; University: East Carolina University; Term: Unknown 1989;
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


DUE: Tuesday April 14 at the start of class
Goals
Assignment Write a Java program complete with full documentation for the following specification.
Hailstone Program
The hailstone sequence, sometimes called the 3 n + 1 sequence, is defined by a function ƒ( n ):
ƒ( n ) = n / 2 if n is even 3 ∗ n + 1 otherwise, if n is odd
We can use the value computed by ƒ as the argument of a new invocation of ƒ as shown below; the successive values of n form the hailstone sequence.
while (n != 1) { n = f(n); }
Although it is conjectured that this loop always terminates, no one has been able to prove it. However, it has been verified by computer for an enormous range of numbers. Several sequences are shown below with the initial value of n on the left.
7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
14 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
Write a program to find the values of n that yields the longest sequence. Prompt the user for two numbers, and limit the search for n to all values between the two numbers (including the endpoints).
Sample interactions your program should produce are given below. User’s input is underlined.
Enter lower limit: 7 Enter upper limit: 20 18 produces the longest hailstone sequence between 7 and 20 inclusive. It’s length is 21.
Technical Issues