Skip to content

Instantly share code, notes, and snippets.

@Slackwise
Last active September 29, 2020 19:27
Show Gist options
  • Save Slackwise/139c4fc1c68708bf0b13f6977b01e871 to your computer and use it in GitHub Desktop.
Save Slackwise/139c4fc1c68708bf0b13f6977b01e871 to your computer and use it in GitHub Desktop.
FizzBuzz in Clojure, composed step-by-step.
(def fizzbuzz-nums (range 1 101))
(defn fizz? [n] (zero? (rem n 3)))
(defn buzz? [n] (zero? (rem n 5)))
(defn fizzbuzz? [n] (and (fizz? n) (buzz? n)))
(defn fizzbuzz [n]
(cond (fizzbuzz? n) "FizzBuzz"
(fizz? n) "Fizz"
(buzz? n) "Buzz"
:else n ))
(def fizzbuzz-list (map fizzbuzz fizzbuzz-nums))
(apply println fizzbuzz-list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment