Skip to content

Instantly share code, notes, and snippets.

@aperiodic
Created November 14, 2014 19:19
Show Gist options
  • Save aperiodic/1ad75d8ee7bec3b35ba4 to your computer and use it in GitHub Desktop.
Save aperiodic/1ad75d8ee7bec3b35ba4 to your computer and use it in GitHub Desktop.
Fizzbuzz Without if, when, and, or, or predicates.
(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