Created
May 25, 2015 22:16
-
-
Save lispm/c143c01c5b52d806249f to your computer and use it in GitHub Desktop.
get the nth prime
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
(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