Python Homework #4

Instructions:

Today's problems are related to the Collatz conjecture and hailstone sequences. These are sequences of numbers that you get by using this rule:

For a number n: Applying this rule repeatedly starting from 5 would result in 5, 16, 8, 4, 2, 1.
  1. Write a function hailstoneNext(n). This should take a positive integer n and return the next number in the hailstone sequence after n.

  2. Use your hailstoneNext to write a function printHailstone(n). This should take a positive integer n and print out the hailstone sequence starting with n. You should use a while loop, looping until n <= 1. Make sure that your code prints out the final 1.

  3. Write one of the following two functions:
  4. Play around with your print, len, or max functions. See if you can find some numbers that give very long sequences or sequences that reach very high numbers. In the comments-to-teacher box, put an n you found, and how high/long the sequence got.

Bonus problem: write some functions to automatically search for the n that gives you the highest/longest sequence, for n in the range 1 to 1000.