17 lines
406 B
AppleScript
17 lines
406 B
AppleScript
on isPrime(n)
|
|
if (n < 4) then return (n > 1)
|
|
if ((n mod 2 is 0) or (n mod 3 is 0)) then return false
|
|
repeat with i from 5 to (n ^ 0.5) div 1 by 6
|
|
if ((n mod i is 0) or (n mod (i + 2) is 0)) then return false
|
|
end repeat
|
|
|
|
return true
|
|
end isPrime
|
|
|
|
-- Test code:
|
|
set output to {}
|
|
repeat with n from -7 to 100
|
|
if (isPrime(n)) then set end of output to n
|
|
end repeat
|
|
return output
|