Created
March 3, 2017 22:31
-
-
Save DataWraith/513d9a74591021872272a9de3229e495 to your computer and use it in GitHub Desktop.
FizzBuzz using lazy seqs in 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
(ns clj-fizzbuzz.core | |
(:gen-class)) | |
(defn hitword | |
[word n] | |
(cycle (cons word (repeat (dec n) nil)))) | |
(defn fizzbuzz | |
[x] | |
(let [fizzes (hitword "Fizz" 3) | |
buzzes (hitword "Buzz" 5)] | |
(doseq [n (range 1 x)] | |
(println | |
(or | |
(not-empty (str | |
(nth fizzes n) | |
(nth buzzes n))) | |
(str n)))))) | |
(defn -main | |
[& args] | |
(fizzbuzz 100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment