Skip to content

Instantly share code, notes, and snippets.

@gigasquid
Created November 7, 2014 23:36
Show Gist options
  • Save gigasquid/dc4686e8245154482be8 to your computer and use it in GitHub Desktop.
Save gigasquid/dc4686e8245154482be8 to your computer and use it in GitHub Desktop.
FizzBuzz without Conditionals
(defn fizzbuzz [n]
(let [all-nums (range 0 n)
folder (fn [fb-str p-num fb-coll]
(mapcat (fn [x] (cons fb-str (rest x)))
(partition-all p-num fb-coll)))
fizz (folder "fizz" 3 all-nums)
buzz (folder "buzz" 5 fizz)
fizzbuzz (folder "fizzbuzz" 15 buzz)]
fizzbuzz))
(fizzbuzz 33)
;; -> ("fizzbuzz" 1 2 "fizz" 4 "buzz" "fizz" 7 8 "fizz" "buzz" 11 "fizz" 13 14 "fizzbuzz" 16 17 "fizz" 19 "buzz" "fizz" 22 23 "fizz" "buzz" 26 "fizz" 28 29 "fizzbuzz" 31 32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment