Sieve of Pritchard: Difference between revisions
Content added Content deleted
m (→{{header|Julia}}: docs) |
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 |
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 |
for w in 1:limit*2 |
||
if members[w] |
|||
n = w + steplength |
|||
while n <= nlimit |
|||
members[n] = true |
|||
ac += 1 |
|||
n += steplength |
|||
end |
|||
end |
end |
||
end |
end |
||
Line 214: | Line 216: | ||
end |
end |
||
np = 5 |
np = 5 |
||
for w in |
for w in 1:limit*2 |
||
if members[w] |
|||
np == 5 && w > prime && (np = w) |
|||
n |
n = prime * w |
||
n > nlimit && break |
|||
rc += 1 |
|||
members[n] = false |
|||
end |
|||
end |
end |
||
np < prime && break |
np < prime && break |