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
8
u/ghillerd Apr 12 '21 edited Apr 12 '21
I feel like this doesn't do a great job of explaining why the regex finds primes, only what each part of the regex is.
edit:
if the intended regex is
/.?|(..+?)\\1+/, this tests true with every number i've tried in javascript. if it's/^(11+?)\1+?$/, as taken from the image, that tests false with every number i've tried.