Created
January 30, 2013 21:52
-
-
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
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
(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