Sieve of Eratosthenes: Difference between revisions

→‎{{header|Julia}}: More concise findall + boolean array based implementation
imported>Tecosaur
(→‎{{header|Julia}}: More concise findall + boolean array based implementation)
Line 10,560:
Alternate version using <code>findall</code> to get all primes at once in the end
 
<syntaxhighlight lang="julia">function sieve(n :: IntInteger)
isprimeprimes = truesfill(true, n)
isprimeprimes[1] = false
for p in 2:n
if isprimeprimes[p] || continue
primes[p .* (2:n÷p)] j .= p * pfalse
if j > n
return findall(isprime)
else
for k in j:p:n
isprime[k] = false
end
end
end
end
findall(primes)
end</syntaxhighlight>
 
Anonymous user