diff --git a/src/Julia/Problems001-050/Problem012.jl b/src/Julia/Problems001-050/Problem012.jl index ed46943..fe7ecfc 100644 --- a/src/Julia/Problems001-050/Problem012.jl +++ b/src/Julia/Problems001-050/Problem012.jl @@ -33,17 +33,17 @@ function Problem12() What is the value of the first triangle number to have over five hundred divisors? =# - function num_divisors(n) - r = isqrt(n) - 2 * count(n % i == 0 for i in 1:r) - (r^2 == n) + function num_divisors(number::Int64) + res = isqrt(number) + return 2 * count(number % i == 0 for i = 1:res) - (res^2 == number) end - triangle = 0 - for i in Iterators.countfrom(1) - triangle += i - if num_divisors(triangle) > 500 - return string(triangle) + ans::Int64 = 0 + for number in Iterators.countfrom(1) + ans += number + if num_divisors(ans) > 500 + return ans end end end