Type hints for improving performance

This commit is contained in:
David Doblas Jiménez 2021-07-24 11:17:25 +02:00
parent c3a4e0a627
commit f5152ece96

View File

@ -16,7 +16,7 @@ function chain_length(n, terms)
break break
end end
if n % 2 == 0 if n % 2 == 0
n = n / 2 n = n ÷ 2
else else
n = 3n + 1 n = 3n + 1
end end
@ -50,7 +50,8 @@ function Problem14()
ans = 0 ans = 0
limit = 1_000_000 limit = 1_000_000
score = 0 score = 0
terms = Dict() terms = Dict{Int, Int}()
sizehint!(terms, limit)
for i in 1:limit for i in 1:limit
terms[i] = chain_length(i, terms) terms[i] = chain_length(i, terms)
if terms[i] > score if terms[i] > score