Skip to content

Instantly share code, notes, and snippets.

KingCode / gist:17f56029834d47b4ffc47b8c4859f995
Created Oct 17, 2016
Unconditional FizzBuzz using a regex, for any multiples m1 (the fizz) < m2 (the buzz), m1 > 1 assumed
View gist:17f56029834d47b4ffc47b8c4859f995
(defn fizzbuzz
([m1 m2 n]
(let [ c #(->> % vector (concat (-> %2 dec (repeat nil))) cycle)
fb-re #"Fizz|Buzz|FizzBuzz"]
(->> [(c "Fizz" m1), (c "Buzz" m2)]
(apply map
(fn [i m1 m2]
(or (re-matches fb-re (str m1 m2))
(range 1 (inc n))))))