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:

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

About CDB 361 Articles
Self-Employed Software Developer, Spark, Property Management, Hobby Forestry, Ex-Teacher, Engineering - Wood, Metal, Electrics & Computers. Outdoors - Walk, Cycle, Kitesurf,

Be the first to comment

Leave a Reply

Your email address will not be published.


*


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