Reduce allocations and formatting
This commit is contained in:
parent
d42df4943d
commit
de1375d3f3
@ -9,6 +9,8 @@ https://projecteuler.net/problem=7 =#
|
||||
|
||||
using BenchmarkTools
|
||||
using Primes
|
||||
using Transducers
|
||||
|
||||
|
||||
function Problem7()
|
||||
#=
|
||||
@ -16,16 +18,21 @@ function Problem7()
|
||||
we can see that the 6th prime is 13.
|
||||
|
||||
What is the 10_001st prime number =#
|
||||
number = 2
|
||||
primeList = Int[]
|
||||
while length(primeList) < 10_001
|
||||
|
||||
count::Int32 = 10_000
|
||||
# 2 is prime but not included to speed-up
|
||||
# 150_000 should be big enough to find 10_000 primes
|
||||
for number::Int32 in 1:2:150_000
|
||||
if isprime(number)
|
||||
append!(primeList, number)
|
||||
count -= 1
|
||||
if count == 0
|
||||
return number
|
||||
end
|
||||
end
|
||||
number += 1
|
||||
end
|
||||
|
||||
return primeList[length(primeList)]
|
||||
# prime_list::Vector{Int64} = primes(250_000)
|
||||
# return prime_list[10_001]
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user