testing number primality using regular expression
Posted: Sun Jul 21, 2013 3:59 pm
i feel i should post this even i can't follow how it works since i have a severe Sore throat, it is about using regular expressions to check primality of numbers. look here
http://www.noulakaz.net/weblog/2007/03/ ... e-numbers/
http://montreal.pm.org/tech/neil_kandalgaonkar.shtml
it will work for small numbers but not for a number like 1234567891 or 123456781 it will say it is prime even it is composite, this is because the capacity of string variable or the engine itself.
feel free to change it or to explain how it works
http://www.noulakaz.net/weblog/2007/03/ ... e-numbers/
http://montreal.pm.org/tech/neil_kandalgaonkar.shtml
it will work for small numbers but not for a number like 1234567891 or 123456781 it will say it is prime even it is composite, this is because the capacity of string variable or the engine itself.
feel free to change it or to explain how it works
Code: Select all
number=13
sNum.s = LSet("1", number,"1") ; make string from 13 "1"'s
CreateRegularExpression(0, "^1?$|^(11+?)\1+$")
a = MatchRegularExpression(0, sNum)
If a =0
Debug ("number = " + number + " is prime")
Else
Debug ("number = " + number + " is not prime")
EndIf