Created
April 14, 2010 09:51
-
-
Save johanlindberg/365626 to your computer and use it in GitHub Desktop.
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
; Fizzbuzz kata (see http://codingdojo.org/cgi-bin/wiki.pl?KataFizzBuzz) | |
(defpackage :fizzbuzz-test | |
(:use :cl :lisp-unit :fizzbuzz)) | |
(in-package :fizzbuzz-test) | |
(define-test fizzbuzz | |
(let ((seq (fizzbuzz::fizzbuzz-sequence))) | |
(assert-equal 100 (length seq)) | |
(assert-equal "1" (nth 0 seq)) | |
(assert-equal "2" (nth 1 seq)) | |
(assert-equal "Fizz" (nth 2 seq)) | |
(assert-equal "4" (nth 3 seq)) | |
(assert-equal "Buzz" (nth 4 seq)) | |
(assert-equal "FizzBuzz" (nth 14 seq)))) |
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
; Fizzbuzz kata (see http://codingdojo.org/cgi-bin/wiki.pl?KataFizzBuzz) | |
(defpackage :fizzbuzz | |
(:use :cl) | |
(:export #:fizzbuzz)) | |
(in-package :fizzbuzz) | |
(defun fizzbuzz () | |
(format t "~{~A~%~}" (fizzbuzz-sequence))) | |
(defun fizzbuzz-sequence () | |
(do* ((i 1 (incf i)) | |
(curr i i) | |
(result '())) | |
((> i 100) (reverse result)) | |
(when (= (mod i 3) 0) | |
(setf curr "Fizz")) | |
(when (= (mod i 5) 0) | |
(setf curr "Buzz")) | |
(when (= (mod i 15) 0) | |
(setf curr "FizzBuzz")) | |
(push (format nil "~A" curr) result))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment