[SICP]分硬币问题
(define (count-change amount)
(cc amount 5))
(define (cc amount kinds-of-coin)
(cond ((= amount 0) 1)
((or (< amount 0) (= kinds-of-coin 0)) 0 )
(else (+ (cc amount (- kinds-of-coin 1))
(cc (- amount (first-denomination kinds-of-coin)) kinds-of-coin))
)
)
)
(define (first-denomination kinds-of-coin)
(cond ((= kinds-of-coin 1) 1)
((= kinds-of-coin 2) 5)
((= kinds-of-coin 3) 10)
((= kinds-of-coin 4) 25)
((= kinds-of-coin 5) 50)
)
)
(count-change 100)
相关文章:
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.





Comments
No comments yet.
Leave a comment