Last active
September 29, 2020 19:27
-
-
Save Slackwise/139c4fc1c68708bf0b13f6977b01e871 to your computer and use it in GitHub Desktop.
FizzBuzz in Clojure, composed step-by-step.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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