longest := 0; n := 0; for i from 1 to 100000 do len := numelems(hailstone(i)); if len > longest then longest := len; n := i; end if; od: printf("The longest Hailstone sequence in the first 100k is n=%d, with %d terms\n",n,longest);