Skip to content

Instantly share code, notes, and snippets.

@kouddy
Created April 9, 2015 01:16
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 kouddy/6cd7e7859cd732201be1 to your computer and use it in GitHub Desktop.
Save kouddy/6cd7e7859cd732201be1 to your computer and use it in GitHub Desktop.
(define (no-more? coin-values) (null? coin-values))
(define (first-denomination coin-values) (car coin-values))
(define (except-first-denomination coin-values) (cdr coin-values))
(define (cc amount coin-values)
(cond ((= amount 0) 1)
((or (< amount 0) (no-more? coin-values)) 0)
(else
(+ (cc amount
(except-first-denomination coin-values))
(cc (- amount
(first-denomination coin-values))
coin-values)))))
(define us-coins (list 50 25 10 5 1))
(define uk-coins (list 100 50 20 10 5 2 1 0.5))
(cc 100 us-coins)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment