Skip to content

Instantly share code, notes, and snippets.

@not-in-stock
Created August 15, 2025 07:45
Show Gist options
  • Select an option

  • Save not-in-stock/1e92baf3ea702c6a2ea68d7ac6c91330 to your computer and use it in GitHub Desktop.

Select an option

Save not-in-stock/1e92baf3ea702c6a2ea68d7ac6c91330 to your computer and use it in GitHub Desktop.
(ns fizz-buzz)
(def default-rules
[{:divisor 3 :token "Fizz"}
{:divisor 5 :token "Buzz"}])
(defn divisable? [n divisor]
(zero? (mod n divisor)))
(def naturals
(iterate inc 1))
(defn rule-stream
[{:keys [divisor token]} driving-seq]
(map (fn [n]
(when (divisable? n divisor)
token))
driving-seq))
(defn- fb-element [n & tokens]
(if-let [tokens (seq (filter some? tokens))]
(apply str tokens)
n))
(defn fizzbuzz
([] (fizzbuzz naturals default-rules))
([driving rules]
(let [streams (map #(rule-stream % driving) rules)]
(apply map fb-element (conj streams driving)))))
(def neganitve-odds
(filter odd? (iterate dec -1)))
(take 20 (fizzbuzz (drop 4 neganitve-odds) default-rules))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment