Last active
September 27, 2015 23:21
-
-
Save verdammelt/6f2ba3ea7cdeeea9b38e to your computer and use it in GitHub Desktop.
raindrops implementation
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 convert (n &optional (cases '((3 . "Pling") (5 . "Plang") (7 . "Plong")))) | |
(let ((results | |
(do* ((cs cases (cdr cs)) | |
(c (car cs) (car cs)) | |
(result (list))) | |
((null cs) (reverse result)) | |
(when (zerop (mod n (car c))) | |
(push (cdr c) result))))) | |
(if results | |
(apply #'concatenate 'string results) | |
(write-to-string n)))) |
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 convert (n &optional (cases '((3 . "Pling") (5 . "Plang") (7 . "Plong")))) | |
(let ((results | |
(loop for c in cases | |
when (zerop (mod n (car c))) collect (cdr c)))) | |
(if results | |
(apply #'concatenate 'string results) | |
(write-to-string n)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(I am annoyed that I never knew you commented here... )
I like your loop example. I'll take it and merge it into the pull request and we'll call this done.