Skip to content

Instantly share code, notes, and snippets.

@nhusher
Created September 16, 2014 18:21
Show Gist options
  • Save nhusher/2110a2c6ebd37fe9c797 to your computer and use it in GitHub Desktop.
Save nhusher/2110a2c6ebd37fe9c797 to your computer and use it in GitHub Desktop.
(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