RosettaCodeData/Task/Hailstone-sequence/Pluto/hailstone-sequence.pluto

27 lines
396 B
Plaintext

function hailstone(n, p=true)
local len = 1
while n > 1 do
++len
if p do io.write(n,'\t') end
n = (n%2==0)?n//2:3*n+1
end
if p do print(1) end
return len
end
hailstone(27)
print("------")
local max = 1
local len = 1
for i = 2,99999 do
local t = hailstone(i,false)
if t > len then
max = i
len = t
end
end
print(max, len)