Hailstone Numbers

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:

  1. Choose any positive integer;
  2. It will be either even or odd.  
  3. If it is odd, multiply by 3 and add 1.  
  4. If it is even, divide by two.  
  5. This will give you a new number.  
  6. Repeat steps 2 to 5 until the process reduces to 1 and you can stop the process.  
  7. Count how many steps it takes to reach 1.  

It can be described using Pseudo Code in the following way:

READ number (positive integer)
SET steps = 0
WHILE number != 1
  IF number is odd THEN
    number = (number * 3) + 1
    number = number / 2
  steps = steps + 1
OUTPUT steps

Your Task

Write a program to perform these calculations and find answers to the following questions:

  1. Do all numbers reach 1?  In other words, are all numbers hailstone numbers?
  2. Can you find any numbers that take a long time to reach 1?  (say a thousand steps?)
  3. What happens if you change the rules?  You may find another interesting property of numbers.

Credit Blundell@MonktonCoombe

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.