diff --git a/src/Julia/Problems001-050/Problem021.jl b/src/Julia/Problems001-050/Problem021.jl index 4398521..fe9239b 100644 --- a/src/Julia/Problems001-050/Problem021.jl +++ b/src/Julia/Problems001-050/Problem021.jl @@ -4,8 +4,9 @@ Created on 05 Aug 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for Problem 21 of Project Euler -https://projecteuler.net/problem=21 =# +Solution for Problem 021 of Project Euler +https://projecteuler.net/problem=21 +=# using BenchmarkTools using Primes @@ -23,10 +24,10 @@ function sum_divisors(n) end counter *= count end - return counter - n end + function is_amicable(n) s = sum_divisors(n) if s == n @@ -37,12 +38,11 @@ function is_amicable(n) if sum_s == n return true end - return false end -function Problem21() +function Problem021() #= Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). @@ -53,20 +53,23 @@ function Problem21() 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. - Evaluate the sum of all the amicable numbers under 10000 =# + Evaluate the sum of all the amicable numbers under 10000 + =# - counter = 0 - for i = 2:10_000 - if is_amicable(i) - counter += i - end - end + # ans = 0 + # for i = 2:10_000 + # if is_amicable(i) + # ans += i + # end + # end - return counter + # return ans + ans = sum(i for i in 2:10_000 if is_amicable(i)) + return ans end -println("Time to evaluate Problem $(lpad(21, 3, "0")):") -@btime Problem21() +println("Took:") +@btime Problem021() println("") -println("Result for Problem $(lpad(21, 3, "0")): ", Problem21()) +println("Result for Problem $(lpad(21, 3, "0")): ", Problem021())