@Jean_Michel this should get you through the night:
function collatz(lim)
max = 1
for i in 1:lim
c = 0
n = SafeUInt64(i)
while n != 1
if n&1==0
n = fld(n,2) # <<< this is the only edit
else
n = 3*n+1
end
c += 1
end
if c>max
max = c
println("at $i new max=$max")
end
end
end
collatz (generic function with 1 method)
julia> collatz(1000)
at 3 new max=7
at 6 new max=8
at 7 new max=16
at 9 new max=19
at 18 new max=20
at 25 new max=23
at 27 new max=111
at 54 new max=112
at 73 new max=115
at 97 new max=118
at 129 new max=121
at 171 new max=124
at 231 new max=127
at 313 new max=130
at 327 new max=143
at 649 new max=144
at 703 new max=170
at 871 new max=178