Move auxiliar function out of main

This commit is contained in:
David Doblas Jiménez 2022-10-09 19:21:37 +02:00
parent 1eb0fc0dc9
commit 948dfb0ff8

View File

@ -9,6 +9,13 @@ https://projecteuler.net/problem=12 =#
using BenchmarkTools using BenchmarkTools
function num_divisors(number::Int64)
res = isqrt(number)
return 2 * count(number % i == 0 for i = 1:res) - (res^2 == number)
end
function Problem12() function Problem12()
#= #=
The sequence of triangle numbers is generated by adding the natural The sequence of triangle numbers is generated by adding the natural
@ -33,12 +40,6 @@ function Problem12()
What is the value of the first triangle number to have over five hundred What is the value of the first triangle number to have over five hundred
divisors? =# divisors? =#
function num_divisors(number::Int64)
res = isqrt(number)
return 2 * count(number % i == 0 for i = 1:res) - (res^2 == number)
end
ans::Int64 = 0 ans::Int64 = 0
for number in Iterators.countfrom(1) for number in Iterators.countfrom(1)
ans += number ans += number