The sieve of Sundaram: Difference between revisions
m
→{{header|AppleScript}}: Optimisation.
m (→{{header|AppleScript}}: Optimisation.) |
|||
Line 115:
end repeat
-- Apply the sieve,
set step to 1
set
set item i of o's lst to 3
repeat with n from 2 to limit by 3
if (item n of o's lst) then
set item i of o's lst to n * 2 + 1
end if
tell (n + 1) to if (item it of o's lst) then
set i to i + 1
set item i of o's lst to it * 2 + 1
end if
if (i ≥ n2) then exit repeat -- Enough primes obtained.
set step to step + 2
repeat with j from (n + 2 + step) to limit by step
Line 126 ⟶ 134:
end repeat
end repeat
-- set beginning of o's lst to 2 -- Uncomment if
return
end sieveOfSundaram
|