Refactor output
This commit is contained in:
parent
39d820cca2
commit
768a3278dd
@ -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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user