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 BenchmarkTools
|
||||||
using Primes
|
using Primes
|
||||||
|
using Transducers
|
||||||
|
|
||||||
|
|
||||||
function Problem7()
|
function Problem7()
|
||||||
#=
|
#=
|
||||||
@ -16,16 +18,21 @@ function Problem7()
|
|||||||
we can see that the 6th prime is 13.
|
we can see that the 6th prime is 13.
|
||||||
|
|
||||||
What is the 10_001st prime number =#
|
What is the 10_001st prime number =#
|
||||||
number = 2
|
|
||||||
primeList = Int[]
|
count::Int32 = 10_000
|
||||||
while length(primeList) < 10_001
|
# 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)
|
if isprime(number)
|
||||||
append!(primeList, number)
|
count -= 1
|
||||||
|
if count == 0
|
||||||
|
return number
|
||||||
|
end
|
||||||
end
|
end
|
||||||
number += 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return primeList[length(primeList)]
|
# prime_list::Vector{Int64} = primes(250_000)
|
||||||
|
# return prime_list[10_001]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user