Sieve of Pritchard: Difference between revisions

Content added Content deleted
m (→‎{{header|Julia}}: change for loop)
Line 186: Line 186:
=={{header|Julia}}==
=={{header|Julia}}==
With the add/remove statistics, the "Removed" figure is a combination of composites and primes under sqrt of limit. Getting about
With the add/remove statistics, the "Removed" figure is a combination of composites and primes under sqrt of limit. Getting about
a 40% speedup from using a BitArray instead of a Set.
a 30x speedup from using a BitArray instead of a Set and integer-range-only for loops.
<syntaxhighlight lang="julia">""" Rosetta Code task rosettacode.org/wiki/Sieve_of_Pritchard """
<syntaxhighlight lang="julia">""" Rosetta Code task rosettacode.org/wiki/Sieve_of_Pritchard """


Line 203: Line 203:
# the last partial wheel (if present)
# the last partial wheel (if present)
if steplength < limit
if steplength < limit
for w in [i for i in eachindex(members) if members[i]]
for w in 1:limit*2
n = w + steplength
if members[w]
while n <= nlimit
n = w + steplength
members[n] = true
while n <= nlimit
ac += 1
members[n] = true
n += steplength
ac += 1
n += steplength
end
end
end
end
end
Line 214: Line 216:
end
end
np = 5
np = 5
for w in [i for i in eachindex(members) if members[i]]
for w in 1:limit*2
np == 5 && w > prime && (np = w)
if members[w]
n = prime * w
np == 5 && w > prime && (np = w)
n > nlimit && break
n = prime * w
rc += 1
n > nlimit && break
members[n] = false
rc += 1
members[n] = false
end
end
end
np < prime && break
np < prime && break