pratham RSS

Home
Archives
Random
Contact

Search Site

Powered by Tumblr
Jul
16th
Thu
permalink

Regex to determine prime numbers

Convert the number to a series of 1s - so 4 becomes 1111 - and use this regex to check if it’s prime.

/^1?$|^(11+?)\1+$/

Very clever. Read this for an explanation.