Safe primes and unsafe primes: Difference between revisions
m
→{{header|AppleScript}}: Minor tidying and optimisation in prime-sieve handler.
(Added AppleScript.) |
m (→{{header|AppleScript}}: Minor tidying and optimisation in prime-sieve handler.) |
||
Line 122:
if (limit < 1) then return {}
-- Build a list initially containing only 'missing values'. For speed, and to reduce the likelihood of hanging,
-- do this by building sublists of at most
script o
property sublists : {}
property numberList : {}
end script
set sublistSize to
set mv to missing value -- Use a single 'missing value' instance for economy.
-- Start with a possible < 1100-item sublist.▼
if (limit mod sublistSize > 0) then▼
▲ set end of o's numberList to mv
if (limit mod sublistSize > 0) then set end of o's sublists to items 1 thru (limit mod sublistSize) of o's numberList▼
set end of o's sublists to o's numberList
▲ -- Then the 1100-item sublist(s), if enough items needed.
▲ repeat sublistSize times
repeat (limit div sublistSize - 1) times
set end of o's sublists to o's numberList's items
end repeat
▲ set end of o's sublists to o's numberList
end if
-- Concatenate them more-or-less evenly.
Line 155 ⟶ 148:
set end of o's numberList to (item (i - 1) of o's sublists) & (item i of o's sublists)
end repeat
if (i < subListCount) then set last item of o's numberList to (
set o's sublists to o's numberList
set subListCount to
end repeat
set o's numberList to beginning of o's sublists
|