Skip to content

Instantly share code, notes, and snippets.

@indiebrain
Created November 19, 2011 02:23
Show Gist options
  • Save indiebrain/1378338 to your computer and use it in GitHub Desktop.
Save indiebrain/1378338 to your computer and use it in GitHub Desktop.
A lazy sequence implementation of the fizzbuzz problem.
(ns fizzbuzz.core)
(defn divisible [x n]
(if (= 0 (mod x n))
:true))
(defn nth-fizzbuzz-term [n]
(cond (and (divisible n 3) (divisible n 5)) :fizzbuzz
(divisible n 3) :fizz
(divisible n 5) :buzz
:else n))
(defn fizzbuzz [x]
(lazy-seq (map nth-fizzbuzz-term (range 1 (inc x)))))
;; Example Usage
;; > (take 10 (drop 100000000 (fizzbuzz.core/fizzbuzz 1500000000)))
;; (100000001 :fizz 100000003 100000004 :fizzbuzz 100000006 100000007 :fizz 100000009 :buzz)
@KAllan357
Copy link

ew you said 'blow your stack.'

@indiebrain
Copy link
Author

indiebrain commented Nov 22, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment