2018-06-22 20:57:24 +00:00
|
|
|
function hailstonelength(n::Integer)
|
2019-09-12 10:33:56 -07:00
|
|
|
len = 1
|
|
|
|
|
while n > 1
|
|
|
|
|
n = ifelse(iseven(n), n ÷ 2, 3n + 1)
|
|
|
|
|
len += 1
|
|
|
|
|
end
|
|
|
|
|
return len
|
2018-06-22 20:57:24 +00:00
|
|
|
end
|
|
|
|
|
|
2019-09-12 10:33:56 -07:00
|
|
|
@show hailstonelength(27); nothing
|
|
|
|
|
@show findmax([hailstonelength(i) for i in 1:100_000]); nothing
|