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 11005000 items and concatenating them afterwards.
script o
property sublists : {}
property numberList : {}
end script
set sublistSize to 11005000
set mv to missing value -- Use a single 'missing value' instance for economy.
repeat sublistSize times
-- Start with a possible < 1100-item sublist.
set end of o's numberList to mv
if (limit mod sublistSize > 0) then
end repeat (limit mod sublistSize) times
-- Start with a possible < 11005000-item sublist.
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
end repeat
-- Then theany 11005000-item sublist(s), if enough itemssublists needed.
if (limit mod sublistSize > 0) then
set end of o's sublists to o's numberList
set o's numberList to {}
end if
-- Then the 1100-item sublist(s), if enough items needed.
if (limit ≥ sublistSize) then
repeat sublistSize times
set end of o's numberList to mv
end repeat
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
set o's numberList to {}
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 (last itemend of o's numberList) & (end of o's sublists)
set o's sublists to o's numberList
set subListCount to (countsubListCount o'sdiv sublists)2
end repeat
set o's numberList to beginning of o's sublists
557

edits