Skip to content

Instantly share code, notes, and snippets.

@kzar
Last active January 2, 2016 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzar/07067986085d63f274b9 to your computer and use it in GitHub Desktop.
Save kzar/07067986085d63f274b9 to your computer and use it in GitHub Desktop.
SICP - counting change in Clojure
(defn change-ways
([amount denominations] (change-ways amount denominations []))
([amount denominations options]
(if (<= amount 0)
[options]
(lazy-seq
(mapcat #(when (>= amount %)
(change-ways (- amount %) denominations (conj options %)))
denominations)))))
; (change-ways 10 [1 2 5 10 20 100])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment