Skip to content

Instantly share code, notes, and snippets.

@martinsson
Created November 19, 2011 23:32
Show Gist options
  • Save martinsson/1379537 to your computer and use it in GitHub Desktop.
Save martinsson/1379537 to your computer and use it in GitHub Desktop.
Solution to code story
(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))))
@st
Copy link

st commented Nov 20, 2011

ça c'est lisible ;-) !
Attention, les règles de type for-all doivent être appliquées dans l'ordre de lecture...
exemple 72 et 73 : FooQix et QixFoo . . .

@martinsson
Copy link
Author

Merci stephane, c'est fixé et surprise le code est plus court. Mais est-il plus compréhensible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment