Created
October 17, 2016 02:53
-
-
Save KingCode/17f56029834d47b4ffc47b8c4859f995 to your computer and use it in GitHub Desktop.
Unconditional FizzBuzz using a regex, for any multiples m1 (the fizz) < m2 (the buzz), m1 > 1 assumed
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
(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)) | |
i)) | |
(range 1 (inc n)))))) | |
([n] | |
(fizzbuzz 3 5 n))) |
Author
KingCode
commented
Oct 17, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment