Skip to content

Instantly share code, notes, and snippets.

@laurentpetit
Created January 30, 2013 21:52
Show Gist options
  • Save laurentpetit/4677475 to your computer and use it in GitHub Desktop.
Save laurentpetit/4677475 to your computer and use it in GitHub Desktop.
Solution Clojure pour l'échoppe de monades de scalaskel. Pour l'algorithme commenté, voir https://gist.github.com/4677385
(defn- changes-envisageables [montant valeur-faciale]
(range 0 (inc (quot montant valeur-faciale))))
(defn- reste-a-rendre [montant nb-pieces valeur-faciale]
(- montant (* nb-pieces valeur-faciale)))
(defn changes [montant]
(let [BAR 7, QIX 11, BAZ 21]
(for [nb-baz (changes-envisageables montant BAZ)
:let [reste (reste-a-rendre montant nb-baz BAZ)]
nb-qix (changes-envisageables reste QIX)
:let [reste (reste-a-rendre reste nb-qix QIX)]
nb-bar (changes-envisageables reste BAR)
:let [nb-foo (reste-a-rendre reste nb-bar BAR)]]
{:foo nb-foo, :bar nb-bar, :qix nb-qix, :baz nb-baz})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment