learning-sicp

My embarrassing half assed SICP run.
git clone https://kaka.farm/~git/learning-sicp
Log | Files | Refs

exercise-14.scm (630B)


      1 #!
      2 
      3 1.14
      4 
      5 !#
      6 
      7 (define (count-change amount)
      8   (cc amount 5))
      9 
     10 (define (cc amount kinds-of-coins)
     11   (cond ((= amount 0) 1)
     12         ((or (< amount 0) (= kinds-of-coins 0)) 0)
     13         (else (+ (cc amount
     14                      (- kinds-of-coins 1))
     15                  (cc (- amount
     16                         (first-denomination kinds-of-coins))
     17                      kinds-of-coins)))))
     18 
     19 (define (first-denomination kinds-of-coins)
     20   (cond ((= kinds-of-coins 1) 1)
     21         ((= kinds-of-coins 2) 5)
     22         ((= kinds-of-coins 3) 10)
     23         ((= kinds-of-coins 4) 25)
     24         ((= kinds-of-coins 5) 50)))
     25 
     26 ;;; XXX
     27 
     28 (count-change 11)
     29 (cc 11 5)