Primes and primality checking
dunbarx
dunbarx at aol.com
Tue Apr 25 14:57:50 EDT 2017
A modification from the web, similar, adapted to LC:
on mouseUp
local tNum
put fld 2 into tNum
put "" into fld 1
put isPrime(tNum) into fld 1
end mouseUp
function isPrime pNum
if pNum ≤ 1 then return false
if pNum ≤ 3 then return true
if pNum mod 2 = 0 or pNum mod 3 = 0 then return false
repeat with y = 5 to sqrt(pNum)
if pNum mod y = 0 or pNum mod (y + 2) = 0 then return false
else return true
end repeat
end isPrime
Same overflow issue at 309 digits.
Craig
--
View this message in context: http://runtime-revolution.278305.n4.nabble.com/Primes-and-primality-checking-tp4714219p4714238.html
Sent from the Revolution - User mailing list archive at Nabble.com.
More information about the use-livecode
mailing list