Last active
November 22, 2023 06:43
-
-
Save frectonz/0235967feae3ecf1c098e5afd5bd6025 to your computer and use it in GitHub Desktop.
From cassidoo's November 20, 2023 newsletter
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 range (x y) | |
(let ((start (min x y)) (end (max x y))) | |
(loop for i from start to end | |
collect i))) | |
(defun primep (num) | |
(cond | |
((<= num 1) nil) | |
((= num 2) t) | |
(t | |
(let ((divisor-count 0)) | |
(loop for i from 2 to (isqrt num) | |
until (= 2 divisor-count) | |
do (when (zerop (rem num i)) | |
(incf divisor-count)) | |
finally (return (zerop divisor-count))))))) | |
(defun between-nums (start end action) | |
(let ((act (if (equal action "even") #'evenp | |
(if (equal action "odd") #'oddp | |
(if (equal action "prime") #'primep | |
(return-from between-nums nil)))))) | |
(remove-if-not act | |
(range start end)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment