-
-
Save tomjack/b99ca5c6e87318540cf5 to your computer and use it in GitHub Desktop.
This file contains 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
(ns com.tomojack.fizzbuzz | |
(:use [clojure.contrib.str-utils :only (str-join)])) | |
(defmacro deffizzer [name fizzmap] | |
`(defn ~name [~'n] | |
(let [~'s (str ~@(for [[modulo string] (sort fizzmap)] | |
`(when (zero? (mod ~'n ~modulo)) ~string)))] | |
(if (empty? ~'s) ~'n ~'s)))) | |
(defn do-fizzer [fizzer] | |
(println (str-join \newline | |
(map fizzer (range 1 101))))) | |
(deffizzer fizzbuzz | |
{3 "Fizz" | |
5 "Buzz"}) | |
(defn do-fizzbuzz [] | |
(do-fizzer fizzbuzz)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment