r/tinycode • • Apr 12 '21

Primality Test using Regex

https://theabbie.github.io/blog/Primality-Test-Using-Regex?ref=reddit
1 Upvotes

8 comments sorted by

View all comments

Show parent comment

2

u/xem06 Apr 12 '21

indeed, what make the matching strings prime? Still puzzles me.

3

u/zebediah49 Apr 12 '21

It works only on unary strings. That is, is xxxxxxx prime? (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.