Skip to content

Instantly share code, notes, and snippets.

@zeraphie
Created March 8, 2016 15:15
Show Gist options
  • Save zeraphie/8c93834d7a405758e07b to your computer and use it in GitHub Desktop.
Save zeraphie/8c93834d7a405758e07b to your computer and use it in GitHub Desktop.
Test if a number is prime 1-liner
function is_prime($number) {
return !preg_match('/^1?$|^(11+?)\1+$/x', str_repeat('1', $number));
}
@zeraphie
Copy link
Author

zeraphie commented Mar 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment