Nickster258

Simple Ruby Primality Test

Nov 1st, 2016
67
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