Created
July 15, 2015 20:56
-
-
Save neodevelop/a602fd6b6e93a13d4108 to your computer and use it in GitHub Desktop.
Prime number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun is-prime (n) | |
(cond ((= 2 n) t) ;; Hard-code "2 is a prime" | |
((= 3 n) t) ;; Hard-code "3 is a prime" | |
((evenp n) nil) ;; If we're looking at an even now, it's not a prime | |
(t ;; If it is divisible by an odd number below its square root, it's not prime | |
(loop for i from 3 to (isqrt n) by 2 | |
never (zerop (mod n i)))))) | |
(print (is-prime 13195)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment