Skip to content
Ex 6.1 Solutions
Back Exercise Part A
Back Exercise Part B
Back Exercise Part C
3. The hailstone sequence starting at a positive integer n is generated by following two simple rules. If n is even, the next number in the sequence is n / 2. If n is odd, the next number in the sequence is 3*n + 1. Repeating this process, the hailstone sequence gets generated. Write a recursive function hailstone(n) which prints the hailstone sequence beginning at n. Stop when the sequence reaches the number 1 (since otherwise, we would loop forever 1, 4, 2, 1, 4, 2, …)