integer: is_prime?
Using “Fermat’s little theorem”…
class Integer
def is_prime?
2 ** self % self == 2 and
3 ** self % self == 3 and
5 ** self % self == 5 and
7 ** self % self == 7
end
end
Using “Fermat’s little theorem”…
class Integer
def is_prime?
2 ** self % self == 2 and
3 ** self % self == 3 and
5 ** self % self == 5 and
7 ** self % self == 7
end
end