Skip to content

Instantly share code, notes, and snippets.

@viebel
Last active August 18, 2022 01:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viebel/b133efde8669d6c0630ee6895c1797c6 to your computer and use it in GitHub Desktop.
Save viebel/b133efde8669d6c0630ee6895c1797c6 to your computer and use it in GitHub Desktop.
the most elegant implementation of FizzBuzz - without a single if
(defn choice [a b]
(clojure.string/join (or (seq a) (seq b))))
(defn fizzbuzz [n]
(let [fizzes (cycle ["" "" "Fizz"])
buzzes (cycle ["" "" "" "" "Buzz"])
words (map str fizzes buzzes)
numbers (map str (rest (range)))]
(take n (map max words numbers))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment