home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 2: PC
/
frozenfish_august_1995.bin
/
bbs
/
d09xx
/
d0963.lha
/
SIOD
/
scm
/
countchangec.scm
< prev
next >
Wrap
Text File
|
1992-09-24
|
3KB
|
69 lines
(define (count-change-rec amount coins)
(cond ((= amount 0) 1)
((or (< amount 0) (null? coins)) 0)
(else (+ (count-change-rec amount (cdr coins))
(count-change-rec (- amount (car coins)) coins)))))
(define (count-change-1 amount)
(let ((50L 0)
(100L 0)
(200L 0)
(changes 0))
(while (< 200L amount)
(while (< (+ 100L 200L) amount)
(while (< (+ 50L 100L 200L) amount)
(set! 50L (+ 50L 50)))
(when (= (+ 50L 100L 200L) amount)
(set! changes (+ changes 1)))
(set! 50L 0)
(set! 100L (+ 100L 100)))
(when (= (+ 100L 200L) amount)
(set! changes (+ changes 1)))
(set! 100L 0)
(set! 200L (+ 200L 200)))
(when (= 200L amount)
(set! changes (+ changes 1)))
changes))
(define (count-change-2 amount)
(let ((50L 0)
(100L 0)
(200L 0)
(changes 0)
(not-done #t))
(while not-done
(if (< (+ 50L 100L 200L) amount)
(set! 50L (+ 50L 50))
(begin (when (= (+ 50L 100L 200L) amount)
(set! changes (+ changes 1)))
(set! 50L 0)
(if (< (+ 100L 200L) amount)
(set! 100L (+ 100L 100))
(begin (set! 100L 0)
(set! 200L (+ 200L 200))
(when (> 200L amount)
(set! not-done #f)))))))
changes))
(define (count-change-3 amount)
(do ((50L 0 (if (< (+ 50L 100L 200L) amount)
(+ 50L 50)
0))
(100L 0 (if (>= (+ 50L 100L 200L) amount)
(if (< (+ 100L 200L) amount)
(+ 100L 100)
0)
100L))
(200L 0 (if (>= (+ 100L 200L) amount)
(+ 200L 200)
200L))
(changes 0 (if (= (+ 50L 100L 200L) amount)
(+ changes 1)
changes)))
((> 200L amount) changes)))
(define (my-while pred exp)
(when (thaw pred)
(thaw exp) (my-while pred exp)))