Created
April 21, 2012 14:17
-
-
Save codeforkjeff/2437313 to your computer and use it in GitHub Desktop.
fizzbuzz in Common Lisp
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
;; Discovered via http://www.adampetersen.se/articles/fizzbuzz.htm | |
;; “Write a program that prints the numbers from 1 to 100. But for | |
;; multiples of three print “Fizz” instead of the number and for the | |
;; multiples of five print “Buzz”. For numbers which are multiples of | |
;; both three and five print “FizzBuzz”.” | |
(defun is-mult-p (n multiple) | |
(= (rem n multiple) 0)) | |
(defun fizzbuzz (&optional n) | |
(let ((n (or n 1))) | |
(if (> n 100) | |
nil | |
(progn | |
(let ((mult-3 (is-mult-p n 3)) | |
(mult-5 (is-mult-p n 5))) | |
(if mult-3 | |
(princ "Fizz")) | |
(if mult-5 | |
(princ "Buzz")) | |
(if (not (or mult-3 mult-5)) | |
(princ n)) | |
(princ #\linefeed) | |
(fizzbuzz (+ n 1))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment