File tree Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 25
25
习题完成情况:
26
26
- 章节一: 43/46
27
27
- 章节二: 88/97
28
- - 章节三: 69 /82
28
+ - 章节三: 70 /82
29
29
- 章节四: TODO
30
30
- 章节五: TODO
31
31
* 运行
Original file line number Diff line number Diff line change 18
18
(provide sign-change-detector make-zero-crossings)
19
19
(define sense-data (list-to-stream '(1 2 1.5 1 0.5 -0.1 -2 -3 -2 -0.5 0.2 3 4 )))
20
20
21
- (define zero-crossings (map-stream sign-change-detector (stream-cdr sense-data) sense-data))
21
+ (define zero-crossings (map-stream sign-change-detector sense-data (cons-stream 0 sense-data) ))
22
22
23
23
(module+ test
24
24
(require rackunit)
28
28
(check-equal? (stream-take-n zero-crossings 13 ) '(0 0 0 0 0 -1 0 0 0 0 1 0 0 ))
29
29
)
30
30
(test-case "Test for zero-crossings "
31
- (check-equal? (stream-take-n zero-crossings 11 ) '(0 0 0 0 -1 0 0 0 0 1 0 ))
31
+ (check-equal? (stream-take-n zero-crossings 13 ) '(0 0 0 0 0 -1 0 0 0 0 1 0 0 ))
32
32
)
33
33
)
Original file line number Diff line number Diff line change
1
+ #lang racket
2
+ (require "stream.rkt " )
3
+ (require "exercise3-74.rkt " )
4
+ (require "exercise3-50.rkt " )
5
+
6
+ (define (smooth input-s)
7
+ (if (or (stream-null? input-s)
8
+ (stream-null? (stream-cdr input-s)))
9
+ the-empty-stream
10
+ (let ((prev (stream-car input-s))
11
+ (cur (stream-car (stream-cdr input-s))))
12
+ (cons-stream
13
+ (/ (+ cur prev) 2 )
14
+ (smooth (stream-cdr input-s))))))
15
+
16
+
17
+ (define (make-zero-crossings-smooth input-s)
18
+ (let ((smooth-stream (smooth input-s)))
19
+ (map-stream sign-change-detector smooth-stream (cons-stream 0 smooth-stream))))
20
+
21
+
22
+ (module+ test
23
+ (require rackunit)
24
+
25
+ (test-case "Test for smooth "
26
+ (define s1 (list-to-stream '(1 3 5 9 13 17 )))
27
+ (check-equal? (stream-take-n (smooth s1) 6 ) '(2 4 7 11 15 ))
28
+ )
29
+
30
+ (test-case "Test for make-zero-crossings-smooth "
31
+ (define sense-data (list-to-stream '(10 2 -2 -10 10 -1 )))
32
+ (define crossings (make-zero-crossings-smooth sense-data))
33
+ (check-equal? (stream-take-n crossings 6 ) '(0 0 -1 1 0 )))
34
+ )
You can’t perform that action at this time.
0 commit comments