Skip to content

Instantly share code, notes, and snippets.

@HemersonTacon
Created October 23, 2020 16:49
Show Gist options
  • Save HemersonTacon/829386b8dff8f76f39208239b4064e49 to your computer and use it in GitHub Desktop.
Save HemersonTacon/829386b8dff8f76f39208239b4064e49 to your computer and use it in GitHub Desktop.
Find out if a number is prime with regex
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 23 17:34:25 2020
@author: hemerson.tacon
"""
import re
def is_prime(n):
return re.match(r"^1?$|^(11+?)\1+$", "1"*n) == None
@HemersonTacon
Copy link
Author

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