Skip to content

Instantly share code, notes, and snippets.

@stevedoyle
Created November 29, 2011 13:18
Show Gist options
  • Save stevedoyle/1404781 to your computer and use it in GitHub Desktop.
Save stevedoyle/1404781 to your computer and use it in GitHub Desktop.
A regex that test for prime numbers
# From: http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/
def is_prime(n)
("1" * n) !~ /^1?$|^(11+?)\1+$/
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment