Created
September 16, 2014 18:21
-
-
Save nhusher/2110a2c6ebd37fe9c797 to your computer and use it in GitHub Desktop.
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 fizz-buzzes | |
"A lazy-seq of the fizz-buzz collection" | |
([] (fizz-buzzes (fizz-buzzer 1) 2)) | |
([n i] (cons n (lazy-seq (fizz-buzzes (fizz-buzzer i) (inc i)))))) | |
(defn fizz-buzzer | |
"Returns string 'Fizz' if divides evenly by 3 | |
Returns string 'Buzz' if divides evenly by 5 | |
Returns string 'FizzBuzz' if divides evenly by 3 and 5 | |
Else returns i" | |
([i] (let [s (str (if (zero? (mod i 3)) "Fizz" "") | |
(if (zero? (mod i 5)) "Buzz" ""))] | |
(if (seq s) s i)))) | |
(take 100 (fizz-buzzes)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment