Hey folks,
This guy over on stackoverflow.com<http://stackoverflow.com> is asking for help
generating and testing very large prime numbers.
http://stackoverflow.com/questions/43600252/generate-and-check-the-primality-of-very-large-numbers-in-livecode
I came up with this:
on mouseUp
local tNum
put fld "testNum" into tNum
put isPrime(tNum) into fld "report"
end mouseUp
function isPrime pNum
if pNum <> 2 AND pNum mod 2 = 0 then
return false
end if
repeat with x = 3 to sqrt(pNum) step 2
if pNum mod x = 0 then
return false
end if
end repeat
return true
end isPrime
However, it doesn’t seem to be reliable for very large numbers (> 100 digits)
as the fellow wants. My math skills are pretty creaky. Anybody want a crack at
this? It’s a fun challenge, plus it can boost LC’s presence on stackoverflow.
Cheers,
Devin
Devin Asay
Director
Office of Digital Humanities
Brigham Young University
_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode