I havent posted anything in a while, and I was thinking about prime numbers for some odd reason... So I decided to port the C/C++ primity function to mIRC.
You can find the original code here: http://docs.google.com/Doc?id=dgrmft6x_0htx3n3fh&hl=en
It should be 99.99% accurate.
Returns $true if N ($1) is a prime number, and $false if it is not.
alias prime {
if ($1 !isnum 2-) return $false
var %x 2, %y $floor($sqrt($1))
while (%x <= %y) {
if (!$calc($1 % %x)) && (%x != $1) break
inc %x
}
if (%y == $calc(%x -1)) return $true
return $false
}
alias prime {
if ($1 !isnum 2- && !$prop) { return 2* $!prime: error; $prime(N)[.up|down] }
if ($istok(up down,$prop,32)) {
var %x = $1
while (%x) {
if ($prime.test(%x)) { return %x }
else { $replace($prop,up,inc,down,dec) %x }
}
}
else { return $prime.test($1) }
}
alias prime.test {
if ($1 !isnum 2-) return $false
var %x 2, %y $floor($sqrt($1))
while (%x <= %y) {
if (!$calc($1 % %x)) && (%x != $1) break
inc %x
}
if (%y == $calc(%x -1)) return $true
return $false
}
Got bored to i added a bit on..
$prime(N)[.up|down] - searches up or down for the next prime num. or just checks with no $prop