Skip to content

Instantly share code, notes, and snippets.

@undees
Created January 5, 2009 08:01
Show Gist options
  • Save undees/43324 to your computer and use it in GitHub Desktop.
Save undees/43324 to your computer and use it in GitHub Desktop.
; SICP change-counting exercise in section 1.2.2
(def coins [1 5 10 25 50])
(defn change-coins [a n]
(cond (zero? a) 1
(neg? a) 0
(zero? n) 0
true (let [d (nth coins (dec n))]
(+ (change-coins a (dec n))
(change-coins (- a d) n)))))
(defn change [a] (change-coins a 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment