Sieve of Pritchard: Difference between revisions
m
blue style formatting
(→Julia: Started by noticing that the max() should be a min(), then noticed there were some other places that could be made more efficient.) |
m (blue style formatting) |
||
Line 93:
=={{header|Julia}}==
Added add/remove statistics. "Removed" figure is a combination of composites and primes under sqrt of limit.
<syntaxhighlight lang="julia">""" Rosetta Code task rosettacode.org/wiki/Sieve_of_Pritchard """
""" Pritchard sieve of primes up to limit
▲function pritchard(limit::T) where T <: Integer
members = Set(one(T))
steplength = 1 # wheel size
Line 113 ⟶ 107:
rtlim = T(floor(sqrt(limit))) # this allows the main loop to go
while prime <= rtlim # one extra time, eliminating the follow-up for
if steplength < limit
for w in members
Line 127 ⟶ 121:
np = 5
for w in sort!(collect(members))
n = prime * w
rc += 1
delete!(members, n)
end
push!(primes, prime)
prime = prime == 2 ? 3 : np
nlimit = min(steplength * prime, limit) # advance wheel limit
end
delete!(members, 1)
verbose && println(
length(primes) + length(members),
return sort!(append!(primes, members))
end
|