class
Register or
log in
to add new notes.
Alex -
August 15, 2008
4 thanks
Cheking if a number is prime?
It’s a class for generating an enumerator for prime numbers and traversing over them.
It’s really slow and will be replaced in ruby 1.9 with a faster one.
Note: if you just want to test whether a number is prime or not, you can use this piece of code:
class Fixnum def prime? ('1' * self) !~ /^1?$|^(11+?)\1+$/ end end 10.prime?