Skip to content

Instantly share code, notes, and snippets.

@AndreaCrotti
Last active October 12, 2017 07:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreaCrotti/09fde05f3d03e43dd1083cff62345d96 to your computer and use it in GitHub Desktop.
Save AndreaCrotti/09fde05f3d03e43dd1083cff62345d96 to your computer and use it in GitHub Desktop.
Recursive implementation of fizzbuzz in Clojure
(defn divides?
[n d]
(= 0 (mod n d)))
(defn remove-factor
[n d]
(if (divides? n d)
(remove-factor (/ n d) d)
n))
(defn fizzbuzz
[n]
(if (divides? n 3)
(str "fizz" (fizzbuzz (remove-factor n 3)))
(if (divides? n 5)
"buzz"
"")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment