Created
June 14, 2021 03:11
-
-
Save tamuhey/911e852a2bc591339feee775d6ce243f to your computer and use it in GitHub Desktop.
Check if a number is prime with regex
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
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