Created
November 14, 2014 19:19
-
-
Save aperiodic/1ad75d8ee7bec3b35ba4 to your computer and use it in GitHub Desktop.
Fizzbuzz Without if, when, and, or, or predicates.
This file contains hidden or 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
(ns conditionless-fizzbuzz.core) | |
(defn if-divisible-by-n | |
[n then-fn else-fn] | |
(fn [x] | |
(let [remainder (mod x n) | |
chosen-fn ({0 then-fn} remainder else-fn)] | |
(chosen-fn x)))) | |
(def fizzbuzzer | |
(if-divisible-by-n | |
3 | |
(fn [x] (str "fizz" ((if-divisible-by-n 5 (constantly "buzz") (constantly nil)) x))) | |
(if-divisible-by-n 5 (constantly "buzz") identity))) | |
(doseq [fizzbuzz (map (comp str fizzbuzzer) (range 100))] | |
(println fizzbuzz)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment