Skip to content

Instantly share code, notes, and snippets.

@kostasdizas
Created January 3, 2017 20:39
Show Gist options
  • Save kostasdizas/2f7ab44e15b81955ff277507763b5533 to your computer and use it in GitHub Desktop.
Save kostasdizas/2f7ab44e15b81955ff277507763b5533 to your computer and use it in GitHub Desktop.
Regex Prime

Regular Expressions Prime Finder

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.

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