Created
August 15, 2025 07:45
-
-
Save not-in-stock/1e92baf3ea702c6a2ea68d7ac6c91330 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (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