Last active
December 10, 2015 11:38
-
-
Save kyleburton/4428579 to your computer and use it in GitHub Desktop.
fizz-buzz.clj
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
;; condition free fizz-buzz solution, based on code from [email protected] to the clojure list | |
;; uses infinite, lazy-sequences | |
(let [three (cycle [nil nil "fizz"]) | |
five (cycle [nil nil nil nil "buzz"])] | |
(defn fizz-buzz [] | |
(map vector (iterate inc 1) three five))) | |
(doseq [tuple (take 30 (fizz-buzz))] | |
(println (apply str (interpose " " (filter identity tuple))))) | |
;; or | |
(doseq [tuple (take 30 (fizz-buzz))] | |
(println (clojure.string/join " " (filter identity tuple)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment