Skip to content

Instantly share code, notes, and snippets.

@joekarma
Forked from codeforkjeff/fizzbuzz.lisp
Created April 22, 2012 06:05
Show Gist options
  • Save joekarma/2459998 to your computer and use it in GitHub Desktop.
Save joekarma/2459998 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 multiple-p (n multiple)
(zerop (mod n multiple)))
(defun fizzbuzz ()
(loop for n from 1 to 100
do (format t "~a~%"
(cond ((multiple-p n 15) "FizzBuzz")
((multiple-p n 5) "Buzz")
((multiple-p n 3) "Fizz")
(t n)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment