Skip to content

Instantly share code, notes, and snippets.

@cgrand
Created January 14, 2013 21:09
Show Gist options
  • Save cgrand/199482c74eb8034c147c to your computer and use it in GitHub Desktop.
Save cgrand/199482c74eb8034c147c to your computer and use it in GitHub Desktop.
(defn change
([n] (change n [:baz 21 :qix 11 :bar 7 :foo 1]))
([n us]
(if-let [[nu vu & us] (seq us)]
(concat (for [mu (range vu (inc n) vu)
m (change (- n mu) us)]
(assoc m nu (/ mu vu)))
(change n us))
(when (zero? n) [{}]))))
@scientific-coder
Copy link

Bravo ! ☺

@laurentpetit
Copy link

Tu peux virer le concat et faire démarrer l range à zéro, non?

@laurentpetit
Copy link

Ah c'est pour ne pas inscrire des :xxx 0 ok

@laurentpetit
Copy link

On pourrait comme dans ma version améliorer le bottom case en le considérant lorsqu'il n'y à plus qu'un type de pièce possible: et c'est alors uniquement si le reminder est à zéro qu'on retourne le quotient entier, sinon liste vide ?

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