WOW, I was able to optimize down to 0.88 seconds by specifying type for a variable like this a::Int64. It's by a factor of 18.6!
Here is the new code:
function main(max_a0)
longest = max_len = len = a = 0
for a0 in 1:max_a0
a = a0
len = 0
while a != 1
len += 1
a::Int64 = ((a%2==0) ? a : 3*a+1)/2
end
if len > max_len
max_len = len
longest = a0
end
end
println("($max_len, $longest)")
end
@time main(1000000)
CMD: $ julia collatz.jl
(329, 837799)
elapsed time: 0.882312881 seconds (1377276 bytes allocated)