-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.2.3-orders-of-growth.rkt
77 lines (74 loc) · 4.46 KB
/
1.2.3-orders-of-growth.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#lang sicp
; exercise 1.14
; (define (count-change amount) (cc amount 5))
;
; (define (cc amount kinds-of-coins)
; (cond ((= amount 0) 1)
; ((or (< amount 0) (= kinds-of-coins 0)) 0)
; (else (+
; (cc amount (- kinds-of-coins 1))
; (cc (- amount (first-denomination kinds-of-coins))
; kinds-of-coins)))))
;
; (define (first-denomination kinds-of-coins)
; (cond ((= kinds-of-coins 1) 1)
; ((= kinds-of-coins 2) 5)
; ((= kinds-of-coins 3) 10)
; ((= kinds-of-coins 4) 25)
; ((= kinds-of-coins 5) 50)))
; (cc 11 5)
; (+ (cc 11 4)
; (+ (cc 11 3)
; (+ (cc 11 2)
; (+ (cc 11 1)
; (+ (cc 11 0) 0
; (cc 10 1))
; (+ (cc 10 0) 0
; (cc 9 1))
; (+ (cc 9 0)) 0
; (cc 8 1)
; (+ (cc 8 0))
; (cc 7 1)
; (+ (cc 7 0))
; (cc 6 1)
; (+ (cc 6 0))
; (cc 5 1)
; (+ (cc 5 0))
; (cc 4 1)
; (+ (cc 4 0))
; (cc 3 1)
; (+ (cc 3 0))
; (cc 2 1)
; (+ (cc 2 0))
; (cc 1 1)
; (+ (cc 1 0) 0
; (cc 0 1)) 1 <- all for this, (cc 11 1) = 1
; (cc 6 2))
; (+ (cc 6 1)
; (+ (cc 6 0) 0
; (cc 5 1))
; (+ (cc 5 0))
; (cc 4 1)
; (+ (cc 4 0))
; (cc 3 1)
; (+ (cc 3 0))
; (cc 2 1)
; (+ (cc 2 0))
; (cc 1 1)
; (+ (cc 1 0) 0
; (cc 0 1)) 1 <- (cc 6 1) = 1, in general (cc n 1) = 1, n >= 1
; (cc 1 2))
; (+ (cc 1 1)
; (+ (cc 1 0)) 0
; (cc 0 1) 1 <- (cc 1 1) = 1
; (cc -4 2)) 0
; -> (cc 6 2) = 2, makes sense (1 1 1 1 1 1) and (5 1)
; (cc 1 3))
; (+ (cc 1 2)
; (+ (cc 1 1)
; (+ (cc 1 0)) 0
; (cc 0 1) 1 <- (cc 1 1) = 1 <- which is to say, only one way to make 1 with 3 coins
; (cc -4 2)) 0
; (cc -9 3)) 0
; (cc -14 4)) 0
; (cc -39 5)) 0