Hey folks,

This guy over on stackoverflow.com<http://stackoverflow.com> is asking for help 
generating and testing very large prime numbers.

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.



Devin Asay
Office of Digital Humanities
Brigham Young University

use-livecode mailing list
Please visit this url to subscribe, unsubscribe and manage your subscription 

Reply via email to