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 2525 习题完成情况:
2626 - 章节一: 43/46
2727 - 章节二: 88/97
28- - 章节三: 69 /82
28+ - 章节三: 70 /82
2929 - 章节四: TODO
3030 - 章节五: TODO
3131* 运行
Original file line number Diff line number Diff line change 1818(provide sign-change-detector make-zero-crossings)
1919(define sense-data (list-to-stream '(1 2 1.5 1 0.5 -0.1 -2 -3 -2 -0.5 0.2 3 4 )))
2020
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) ))
2222
2323(module+ test
2424 (require rackunit)
2828 (check-equal? (stream-take-n zero-crossings 13 ) '(0 0 0 0 0 -1 0 0 0 0 1 0 0 ))
2929 )
3030 (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 ))
3232 )
3333 )
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