Skip to content

Instantly share code, notes, and snippets.

@neodevelop
Created July 15, 2015 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neodevelop/a602fd6b6e93a13d4108 to your computer and use it in GitHub Desktop.
Save neodevelop/a602fd6b6e93a13d4108 to your computer and use it in GitHub Desktop.
Prime number
(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