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:
 Choose any positive integer;
 It will be either even or odd.
 If it is odd, multiply by 3 and add 1.
 If it is even, divide by two.
 This will give you a new number.
 Repeat steps 2 to 5 until the process reduces to 1 and you can stop the process.
 Count how many steps it takes to reach 1.
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
Be the first to comment