Skip to content

Instantly share code, notes, and snippets.

@verdammelt
Last active September 27, 2015 23:21
Show Gist options
  • Save verdammelt/6f2ba3ea7cdeeea9b38e to your computer and use it in GitHub Desktop.
Save verdammelt/6f2ba3ea7cdeeea9b38e to your computer and use it in GitHub Desktop.
raindrops implementation
(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))))
(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))))
@verdammelt
Copy link
Author

(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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment