Created
November 19, 2011 23:32
-
-
Save martinsson/1379537 to your computer and use it in GitHub Desktop.
Solution to code story
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
(def number) | |
(defn- for-all [fbq-digits text] | |
(let [extra-fbqs (for [d (str number) :when (fbq-digits d)] (fbq-digits d))] | |
(concat text extra-fbqs))) | |
(defn if-divisible-by [[div suffix] text] | |
(if (zero? (rem number div)) | |
(conj text suffix) | |
text)) | |
(defn- number-or-text [text] | |
(if (empty? text) | |
(str number) | |
text)) | |
(defn fbq [n] | |
(binding [number n] | |
(apply str | |
(->> [] | |
(if-divisible-by [3 "Foo"]) | |
(if-divisible-by [5 "Bar"]) | |
(if-divisible-by [7 "Qix"]) | |
(for-all {\3 "Foo" \5 "Bar" \7 "Qix"}) | |
number-or-text)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Merci stephane, c'est fixé et surprise le code est plus court. Mais est-il plus compréhensible?