Created
May 27, 2011 16:20
-
-
Save haggen/995608 to your computer and use it in GitHub Desktop.
Find out if given number is prime
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
#!/usr/bin/ruby | |
# Find out if given number is prime | |
# based on http://zmievski.org/2010/08/the-prime-that-wasnt by ANDREI ZMIEVSKI | |
# inspired by http://pastebin.com/PGT94gdF by MAURO BARALDI | |
def prime?(n) | |
n = '1' * n.to_i | |
n == '1' or !n[/^1?$|^(11+?)\1+$/] | |
end | |
puts prime?(ARGV[0]), "\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment