ID:257766
 
//Title: Prime Number Checker
//Credit to: Xx Dark Wizard xX
//Contributed by: Xx Dark Wizard xX

/*
This will check any number and will return 1 if it is a
prime number and 0 otherwise.
*/

proc
IsPrime(n)
if(n % 2 == 0 && n != 2) // even number
return 0
var/s = sqrt(n) // avoid constant checking since sqrt() is slow
for(var/i = 3, i <= s, i+=2)
if(n % i == 0) // it isn't prime
return 0
return 1 // its a prime number


///*
//Testing code/sample implementation
mob
verb
Check(n as num)
if(IsPrime(n))
src << "[n] is a prime number"
else
src << "[n] is not a prime number"
//*/
Please follow the format, DarkWiz! I've had to go through and change quite a few of yours. If something doesn't conform to the format, it doesn't get protected under the licence and would probably just fall under standard copyright (i.e., undistributable).
I think Lummox JR posted a more efficient version of this somewhere. I'll search for it.

Edit:
proc/IsPrime(n)
var/p=3,psq=9
if(n>2 && !(n%2)) return 0
while(psq<=n)
if(!(n%p)) return 0
psq+=4*p+4; p+=2
return 1