Created
March 8, 2016 15:15
-
-
Save zeraphie/8c93834d7a405758e07b to your computer and use it in GitHub Desktop.
Test if a number is prime 1-liner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function is_prime($number) { | |
return !preg_match('/^1?$|^(11+?)\1+$/x', str_repeat('1', $number)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
via http://stackoverflow.com/a/24769490