program hailstone_sequence; hail27 := hailstone(27); print("The hailstone sequence for the number 27 has", #hail27, "elements,"); print("starting with", hail27(..4), "and ending with", hail27(#hail27-3..)); sizes := [#hailstone(n) : n in [1..99999]]; maxsize := max/sizes; maxelem := [n : n in [1..#sizes] | sizes(n) = maxsize](1); print("The number < 100,000 with the longest hailstone sequence is",maxelem); print("The length of its sequence is",sizes(maxelem)); proc hailstone(n); seq := []; loop doing seq with:= n; while n/=1 do if even n then n div:= 2; else n := 3*n + 1; end if; end loop; return seq; end proc; end program;