Guest User

Untitled

a guest
May 27th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.33 KB | None | 0 0
  1. class Integer
  2.  
  3. def prime?
  4.     num = self.abs
  5.     return false if num == 0 || num == 1
  6.     return true if (1..num-1).inject {|acc, val| (acc * val) % num} == num - 1
  7.     false
  8. end
  9.  
  10. end
  11.  
  12. #Uses Wilson's theorem to check for primality.
  13. #Pros: Is always correct
  14. #Cons: Even less efficient than trial division - not practical at all
Add Comment
Please, Sign In to add comment