10-24-2013 Lab

posted Oct 24, 2013, 5:41 AM by Samuel Konstantinovich   [ updated Oct 24, 2013, 8:07 AM ]
Hailstone:

Hailstone is a numerical sequence that ends at 1 and starts at any positive integer.

The next number in the sequence depends on the current number.
(hail n)
(= n 1) -> 1  (stop)
(even? n) ->  n/2
(odd? n) -> 3n + 1



hailstone of 1 -> 1
hailstone of 2 -> 2 1
hailstone of 3 -> 3 10 5 16 8 4 2 1
hailstone of 4 -> 4 2 1
hailstone of 5 -> 5 16 8 4 2 1
etc.

Lab / Complete at home:
You will write functions that use this sequence.
1. (hailLen n) will tell you the length of the hailstone sequence started by n.
(hailLen 1) -> 1
(hailLen 2) -> 2
(hailLen 3) -> 8
(hailLen 5) -> 6
etc.

2. (maxHail n) will tell you the largest number in the hailstone sequence started by n.
(maxHail 3) -> 10
(maxHail 4) -> 4
(maxHail 5) -> 16
(maxHail 17) -> 52

Comments