SHARE
TWEET

Simple Ruby Primality Test

Nickster258 Nov 1st, 2016 (edited) 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def isPrime (n)
  2.         return true if n==1
  3.         if n%2==0
  4.                 return true if n==2
  5.                 return false
  6.         end
  7.         for i in (3..Math.sqrt(n)).step(2)
  8.                 return false if n%i==0
  9.         end
  10.         return true
  11. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top