The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
<ul>
<li>If n is <b>1</b> then the sequence ends.</li>
<li>If n is <b>even</b> then the next n of the sequence <code>= n/2</code></li>
<li>If n is <b>odd</b> then the next n of the sequence <code>= (3 * n) + 1</code></li>
</ul>
The (unproven) <ahref="https://en.wikipedia.org/wiki/Collatz conjecture"title="wp: Collatz conjecture"target="_blank">Collatz conjecture</a> is that the hailstone sequence for any starting number always terminates.
The hailstone sequence is also known as hailstone numbers (because the values are usually subject to multiple descents and ascents like hailstones in a cloud), or as the Collatz sequence.
<li>Create a routine to generate the hailstone sequence for a number.</li>
<li>Use the routine to show that the hailstone sequence for the number 27 has 112 elements starting with <code>27, 82, 41, 124</code> and ending with <code>8, 4, 2, 1</code></li>
<li>Show the number less than 100,000 which has the longest hailstone sequence together with that sequence's length. (But don't show the actual sequence!)</li>