diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-06-20 20:10:05 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-06-20 20:10:05 +0200 |
| commit | e794020d8b881ede726338be50eaa461a134889f (patch) | |
| tree | 99f32380378fa6813d7ccf15b56d8b48fcd263c2 /julia/010-summation_of_primes.jl | |
| parent | 16a3e5fc6728f1c0d414983f6e1fc3fc160034b3 (diff) | |
| download | project_euler-e794020d8b881ede726338be50eaa461a134889f.tar.gz project_euler-e794020d8b881ede726338be50eaa461a134889f.tar.bz2 project_euler-e794020d8b881ede726338be50eaa461a134889f.zip | |
Refactoging julia problems with function chainning
Diffstat (limited to 'julia/010-summation_of_primes.jl')
| -rw-r--r-- | julia/010-summation_of_primes.jl | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/julia/010-summation_of_primes.jl b/julia/010-summation_of_primes.jl index 1e93a4f..5918d36 100644 --- a/julia/010-summation_of_primes.jl +++ b/julia/010-summation_of_primes.jl @@ -12,12 +12,14 @@ function eratosthenes_sieve(stop) while true prime = pop!(ns) push!(primes, prime) - if prime > ceil(sqrt(stop)) + if prime > ceil(Integer, √stop) return append!(primes, ns) break end - ns = filter(n -> n % prime != 0, ns) + filter!(n -> n % prime != 0, ns) end end -println(sum(eratosthenes_sieve(2_000_000 - 1))) +result = eratosthenes_sieve(2_000_000 - 1) |> sum + +println(result) |
