T
Tim Pease
This is a one-liner Ruby script that will tell you if a given number is prime.
ruby -wle 'puts "Prime" unless ("1" * ARGV[0].to_i) =~
/^1$|^(11+?)\1+$/' [number]
I cannot take credit for this one -- it originally came from Perl. The
website listed below gives the full explanation of how the regexp
works.
http://montreal.pm.org/tech/neil_kandalgaonkar.shtml
I highly recommend reading this if you want to flex your regexp muscles today.
Blessings,
TwP
ruby -wle 'puts "Prime" unless ("1" * ARGV[0].to_i) =~ /^1$|^(11+?)\1+$/' 42
It may be the answer to life, the universe, and everything, but it
certainly isn't prime!
ruby -wle 'puts "Prime" unless ("1" * ARGV[0].to_i) =~
/^1$|^(11+?)\1+$/' [number]
I cannot take credit for this one -- it originally came from Perl. The
website listed below gives the full explanation of how the regexp
works.
http://montreal.pm.org/tech/neil_kandalgaonkar.shtml
I highly recommend reading this if you want to flex your regexp muscles today.
Blessings,
TwP
ruby -wle 'puts "Prime" unless ("1" * ARGV[0].to_i) =~ /^1$|^(11+?)\1+$/' 42
It may be the answer to life, the universe, and everything, but it
certainly isn't prime!