A Hailstone Number is a number relating to a sequence of integers that go up and down like a Hailstone in a cloud before it eventually falls to the ground. A hailstone number will eventually reach 1 before becoming stuck the short sequence of 4,2, 1.
One possible hailstone method is:
It can be described using Pseudo Code in the following way:
1 2 3 4 5 6 7 8 9 |
READ number (positive integer) SET steps = 0 WHILE number != 1 IF number is odd THEN number = (number * 3) + 1 ELSE number = number / 2 steps = steps + 1 OUTPUT steps |
Your Task
Write a program to perform these calculations and find answers to the following questions:
Do all numbers reach 1? In other words, are all numbers hailstone numbers?
Can you find any numbers that take a long time to reach 1? (say a thousand steps?)
What happens if you change the rules? You may find another interesting property of numbers.
Credit Blundell@MonktonCoombe