Skip to content

Instantly share code, notes, and snippets.

@DataWraith
Created March 3, 2017 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DataWraith/513d9a74591021872272a9de3229e495 to your computer and use it in GitHub Desktop.
Save DataWraith/513d9a74591021872272a9de3229e495 to your computer and use it in GitHub Desktop.
FizzBuzz using lazy seqs in Clojure.
(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