Created
October 11, 2012 16:03
-
-
Save meadhikari/3873415 to your computer and use it in GitHub Desktop.
First common lisp function
This file contains hidden or 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
;Add all the natural numbers below one thousand that are multiples of 3 or 5. | |
(defun sum-to-last (x) | |
(cond ((eql x 0) | |
0) | |
(t | |
(let ((mod3 (eql (mod x 3) 0)) | |
(mod5 (eql (mod x 5) 0)) | |
) | |
(cond ((or mod3 mod5) | |
(+ x (sum-to-last (1- x))) | |
) | |
(t (sum-to-last (1- x))) | |
))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment