Program To Calculate Hailstone Sequences
A specific Hailstone sequence can be easily computed, as is shown by this pseudocode example:
- function hailstone(n)
- while n > 1
- show n
- if n is odd then
- set n = 3n + 1
- else
- set n = n / 2
- endif
- endwhile
- show n
- while n > 1
This program halts when the sequence reaches 1, in order to avoid printing an endless cycle of 4, 2, 1. If the Collatz conjecture is true, the program will always halt (stop) no matter what positive starting integer is given to it.
Read more about this topic: Collatz Conjecture
Famous quotes containing the words program, calculate and/or hailstone:
“They had their fortunes to make, everything to gain and nothing to lose. They were schooled in and anxious for debates; forcible in argument; reckless and brilliant. For them it was but a short and natural step from swaying juries in courtroom battles over the ownership of land to swaying constituents in contests for office. For the lawyer, oratory was the escalator that could lift a political candidate to higher ground.”
—Federal Writers Project Of The Wor, U.S. public relief program (1935-1943)
“However others calculate the cost,
To us the final aggregate is one,
One with a name, one transferred to the blest;
And though another stoops and takes the gun,
We cannot add the second to the first.”
—Karl Shapiro (b. 1913)
“You are no surer, no,
Than is the coal of fire upon the ice,
Or hailstone in the sun.”
—William Shakespeare (15641616)