Skip to content

Instantly share code, notes, and snippets.

@lispm
Created May 25, 2015 22:16
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 lispm/c143c01c5b52d806249f to your computer and use it in GitHub Desktop.
Save lispm/c143c01c5b52d806249f to your computer and use it in GitHub Desktop.
get the nth prime
(defmethod get-prime ((a integer))
(let ((vector (make-array 100)))
(setf (aref vector 0) 2)
(loop for i from 1 upto a do
(loop for j from (1+ (aref vector (1- i))) do
(when (= i (loop for k below i
until (zerop (mod j (aref vector k)))
finally (return k)))
(setf (aref vector i) j)
(return))))
(aref vector a)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment