Skip to content

Instantly share code, notes, and snippets.

@Jun-Dai
Created September 24, 2013 23:30
Show Gist options
  • Save Jun-Dai/6692804 to your computer and use it in GitHub Desktop.
Save Jun-Dai/6692804 to your computer and use it in GitHub Desktop.
coins in scheme
(define (cc amount kinds-of-coins)
(if (or (< amount 0) (= kinds-of-coins 0)) 0
(+ (cc amount (- kinds-of-coins 1))
(if (= amount (first-denomination kinds-of-coins)) 1 0)
(cc (- amount (first-denomination kinds-of-coins)) kinds-of-coins))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment