Skip to content

Instantly share code, notes, and snippets.

@dfuenzalida
Created April 8, 2013 14:17
Show Gist options
  • Save dfuenzalida/5337096 to your computer and use it in GitHub Desktop.
Save dfuenzalida/5337096 to your computer and use it in GitHub Desktop.
The FizzBuzz problem in "moderately idiomatic" Clojure
(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