Convert the number to an n-long string and then try to split it up into groups containing 2 .. n characters with no remainder. If there is a match it is not prime.
Created
January 3, 2017 20:39
-
-
Save kostasdizas/2f7ab44e15b81955ff277507763b5533 to your computer and use it in GitHub Desktop.
Regex Prime
This file contains hidden or 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
import re | |
def is_prime(n): | |
return not re.match(".?$|(..+?)\1+$", "0" * n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment