Skip to content

Instantly share code, notes, and snippets.

@hellerve
Last active November 23, 2015 11:31
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 hellerve/87b761af4d5e6b23a4f7 to your computer and use it in GitHub Desktop.
Save hellerve/87b761af4d5e6b23a4f7 to your computer and use it in GitHub Desktop.
This is a zepto solution to a problem described in SICP 1.2.2
;; Solution to:
;; How many different ways can we make change of $ 1.00, given half-dollars, quarters, dimes, nickels, and pennies?
;; More generally, can we write a procedure to compute the number of ways to change any given amount of money?
;;
;; Example usage for $1.00: (count-change 100) => 292
;; This computation takes around 0.6 secs on my machine in zepto.
(define (count-change amount)
(cc amount 5))
(define (cc amount kinds-of-coins)
(cond ((= amount 0) 1)
((or (< amount 0) (= kinds-of-coins 0)) 0)
(else (+ (cc amount
(- kinds-of-coins 1))
(cc (- amount
(first-denomination kinds-of-coins))
kinds-of-coins)))))
(define first-denomination (hash-map [1 1] [2 5] [3 10] [4 25] [5 50]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment