Sieve of Pritchard: Difference between revisions

Content added Content deleted
(→‎{{header|Julia}}: loop limits too high, was over including numbers)
Line 235: Line 235:
rc = 1 # removed count, since 1 will be removed at the end
rc = 1 # removed count, since 1 will be removed at the end
rtlim = T(isqrt(limit)) # this allows the main loop to go
rtlim = T(isqrt(limit)) # this allows the main loop to go
while prime <= rtlim # one extra time, eliminating the follow-up for
while prime < rtlim # one extra time, eliminating the follow-up for
# the last partial wheel (if present)
# the last partial wheel (if present)
if steplength < limit
if steplength < limit
for w in 1:length(members)
for w in 1:steplength
if members[w]
if members[w]
n = w + steplength
n = w + steplength
Line 252: Line 252:
np = 5
np = 5
mcopy = copy(members)
mcopy = copy(members)
for w in 1:length(members)
for w in 1:nlimit
if mcopy[w]
if mcopy[w]
np == 5 && w > prime && (np = w)
np == 5 && w > prime && (np = w)
Line 272: Line 272:
length(primes) + length(newprimes),
length(primes) + length(newprimes),
)
)
return sort!(append!(primes, newprimes))
return append!(primes, newprimes)
end
end