Created
April 4, 2020 05:25
-
-
Save madosuki/0edf91458e6a16f89244b2aee040ae40 to your computer and use it in GitHub Desktop.
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 sieve-of-eratosthenes (&optional (target-number 128)) | |
(let ((search-list (loop for i from 2 to target-number | |
if (/= (mod i 2) 0) | |
collect i)) | |
(result (list 2)) | |
(range-max (sqrt target-number))) | |
(labels ((calculator () | |
(if (or (null (car search-list)) (>= (sqrt (car search-list)) range-max)) | |
(nreverse result) | |
(progn | |
(push (car search-list) result) | |
(setq search-list (remove-if #'(lambda (n) (= (mod n (car result)) 0)) search-list)) | |
(calculator))))) | |
(calculator)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment