-
-
Save kzar/07067986085d63f274b9 to your computer and use it in GitHub Desktop.
SICP - counting change in Clojure
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 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