Skip to content

Instantly share code, notes, and snippets.

@codeforkjeff
Created April 21, 2012 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codeforkjeff/2437313 to your computer and use it in GitHub Desktop.
Save codeforkjeff/2437313 to your computer and use it in GitHub Desktop.
fizzbuzz in Common Lisp
;; 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