**this is project 5**

## Project Description:

hailstone sequence (due 28 feb 2015)

take any natural number n. if n is even, divide it by 2 to get n // 2. if n is odd, multiply by 3 and add 1 to obtain 3 * n + 1. repeat the process indefinitely. the conjecture is that no matter what number you start with, you will eventually reach 1.

this conjecture has never been proved. but it has been verified on the computer for all starting values up to 20 * 258. to disprove this conjecture one has to find a single starting number that goes into a cycle that does not contain 1.

the function can be written as follows:

f ( n ) = ( n // 2 ) if n is even

f ( n ) = ( 3 * n + 1 ) if n is odd

for a given starting number, this function generates a series of numbers ending at 1 that is called the hailstone sequence. the hailstone sequences for starting numbers 7, 8, and 9 are:

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

all sequences tested so far end in an endless cycle of 4, 2, and 1. hence the sequences are halted when they reach 1. we will define the cycle length of a sequence to be the number of steps it takes from the starting number to reach 1. here are the cycle lengths of a few starting numbers:

number cycle length

1 0

2 1

3 7

4 2

5 5

in your program you will verify this conjecture in a user defined range. you will prompt the user to enter the starting number of the range and the ending number. after you have read both the numbers, you will check if both numbers are positive (> 0) individually and then you will check that the starting number in the user defined range is strictly less than the ending number in that range. if the input does not meet the specifications, prompt the user to enter both the starting and ending numbers.

once the beginning and ending of the range have been verified, your program will compute the cycle length for each of the numbers in that range inclusive of the end points. your program will print out the number that has the largest cycle length and what that cycle length is. if there are two or more numbers that have the same largest cycle length, then print only the last number (greatest number) that has the largest cycle length.

your sample session will look like this:

enter starting number of the range: 1

enter ending number of the range: 5

the number 3 has the longest cycle length of 7.

in your program all your computations will be in the function main(). you must use nested loops to obtain your results.

the program that you will be writing will be called hailstone.py. we will be looking at good documentation, design, and adherence to the coding convention as discussed in class. your file hailstone.py will have the following header:

# file: hailstone.py

# description:

# student name:

# student ut eid:

# course name: cs 303e

# unique number:

# date created:

# date last modified:

use the canvas program to submit your hailstone.py file. we should receive your work by 11 pm on saturday, 28 feb 2015. there will be substantial penalties if you do not adhere to the guidelines.

take any natural number n. if n is even, divide it by 2 to get n // 2. if n is odd, multiply by 3 and add 1 to obtain 3 * n + 1. repeat the process indefinitely. the conjecture is that no matter what number you start with, you will eventually reach 1.

this conjecture has never been proved. but it has been verified on the computer for all starting values up to 20 * 258. to disprove this conjecture one has to find a single starting number that goes into a cycle that does not contain 1.

the function can be written as follows:

f ( n ) = ( n // 2 ) if n is even

f ( n ) = ( 3 * n + 1 ) if n is odd

for a given starting number, this function generates a series of numbers ending at 1 that is called the hailstone sequence. the hailstone sequences for starting numbers 7, 8, and 9 are:

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

all sequences tested so far end in an endless cycle of 4, 2, and 1. hence the sequences are halted when they reach 1. we will define the cycle length of a sequence to be the number of steps it takes from the starting number to reach 1. here are the cycle lengths of a few starting numbers:

number cycle length

1 0

2 1

3 7

4 2

5 5

in your program you will verify this conjecture in a user defined range. you will prompt the user to enter the starting number of the range and the ending number. after you have read both the numbers, you will check if both numbers are positive (> 0) individually and then you will check that the starting number in the user defined range is strictly less than the ending number in that range. if the input does not meet the specifications, prompt the user to enter both the starting and ending numbers.

once the beginning and ending of the range have been verified, your program will compute the cycle length for each of the numbers in that range inclusive of the end points. your program will print out the number that has the largest cycle length and what that cycle length is. if there are two or more numbers that have the same largest cycle length, then print only the last number (greatest number) that has the largest cycle length.

your sample session will look like this:

enter starting number of the range: 1

enter ending number of the range: 5

the number 3 has the longest cycle length of 7.

in your program all your computations will be in the function main(). you must use nested loops to obtain your results.

the program that you will be writing will be called hailstone.py. we will be looking at good documentation, design, and adherence to the coding convention as discussed in class. your file hailstone.py will have the following header:

# file: hailstone.py

# description:

# student name:

# student ut eid:

# course name: cs 303e

# unique number:

# date created:

# date last modified:

use the canvas program to submit your hailstone.py file. we should receive your work by 11 pm on saturday, 28 feb 2015. there will be substantial penalties if you do not adhere to the guidelines.

Skills Required:

Project Stats:

**Price Type:** Negotiable

Expired

Total Proposals: 2

1 Current viewers

*l*38 Total views

### Proposals

Proposals
Reputation
Price offered