Created
April 8, 2013 14:17
-
-
Save dfuenzalida/5337096 to your computer and use it in GitHub Desktop.
The FizzBuzz problem in "moderately idiomatic" Clojure
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
(defn fizzbuzz | |
"Prints the numbers from 1 to 100. But for multiples of three prints | |
'Fizz' instead of the number and for the multiples of five prints | |
'Buzz'. For numbers which are multiples of both three and five prints | |
'FizzBuzz'" | |
[] | |
(doall | |
(map | |
#(println | |
(some | |
(fn [x] (when (seq x) x)) ;; print the first non-empty from: | |
[(str (nth ["Fizz"] (mod % 3) "") (nth ["Buzz"] (mod % 5) "")) | |
(str %)])) | |
(range 1 101)))) | |
(fizzbuzz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment