Skip to content

Instantly share code, notes, and snippets.

@boogie666
Last active December 5, 2017 00:18
Show Gist options
  • Save boogie666/552d9fcc8ac1942395ec233ac68f60ad to your computer and use it in GitHub Desktop.
Save boogie666/552d9fcc8ac1942395ec233ac68f60ad to your computer and use it in GitHub Desktop.
Lazy Functional FizzBuzz in Clojure
(ns fizzbuzz.core)
(defn str-max [a b]
(if (<= (compare a b) 0) b a))
(def fizzes (cycle ["" "" "fizz"]))
(def buzzes (cycle ["" "" "" "" "buzz"]))
(def numbers (sequence (comp (map inc) (map str)) (range)))
(def pattern (map str fizzes buzzes))
(def fizzbuzz (map str-max numbers pattern))
(doseq [x (take 100 fizzbuzz)] (println x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment