Skip to content

Instantly share code, notes, and snippets.

@haggen
Created May 27, 2011 16:20
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 haggen/995608 to your computer and use it in GitHub Desktop.
Save haggen/995608 to your computer and use it in GitHub Desktop.
Find out if given number is prime
#!/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