Skip to content

Instantly share code, notes, and snippets.

@tamuhey
Created June 14, 2021 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamuhey/911e852a2bc591339feee775d6ce243f to your computer and use it in GitHub Desktop.
Save tamuhey/911e852a2bc591339feee775d6ce243f to your computer and use it in GitHub Desktop.
Check if a number is prime with regex
import re
def prime(n: int):
return re.match(r"^(aa+?)\1+$", "a" * n) is None
for i in range(2, 10000):
if prime(i):
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment