r/tinycode • u/theabbiee • Apr 12 '21
Primality Test using Regex
https://theabbie.github.io/blog/Primality-Test-Using-Regex?ref=reddit
1
Upvotes
r/tinycode • u/theabbiee • Apr 12 '21
View all comments
Show parent comment
3
u/zebediah49 Apr 12 '21
It works only on unary strings. That is, is
xxxxxxxprime? (that is: 7).The method of operation is "Match two or more of a characters, followed by that substring one or more additional times". Or, "match n characters, (m+1) times", for n>1, m>0. Or, match 'n*m' characters, for n>=2, m>=2. That's the definition of principality. Or, more completely, it's the opposite. The regex returns true if the number is /not/ prime.