File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 2525 习题完成情况:
2626 - 章节一: 43/46
2727 - 章节二: 88/97
28- - 章节三: 68 /82
28+ - 章节三: 69 /82
2929 - 章节四: TODO
3030 - 章节五: TODO
3131* 运行
Original file line number Diff line number Diff line change 1+ #lang racket
2+ (require "stream.rkt " )
3+ (require "exercise3-74.rkt " )
4+
5+ (define (make-zero-crossings
6+ input-stream last-value)
7+ (let ((avpt
8+ (/ (+ (stream-car input-stream)
9+ last-value)
10+ 2 )))
11+ (cons-stream
12+ (sign-change-detector avpt last-value)
13+ (make-zero-crossings
14+ ;; last-value 参数传入的是平均值,而非前一个值
15+ (stream-cdr input-stream) avpt))))
16+
17+ (define (make-zero-crossings-smooth input-stream last-value last-avg)
18+ (if (stream-null? input-stream)
19+ the-empty-stream
20+ (let ((avpt
21+ (/ (+ (stream-car input-stream)
22+ last-value)
23+ 2 )))
24+ (cons-stream
25+ (sign-change-detector avpt last-avg)
26+ (make-zero-crossings-smooth
27+ (stream-cdr input-stream)
28+ (stream-car input-stream)
29+ avpt)))))
30+
31+ (module+ test
32+ (require rackunit)
33+
34+ (test-case "Test for make-zero-crossings-smooth "
35+ (define sense-data (list-to-stream '(10 2 -2 -10 10 -1 )))
36+ (define crossings (make-zero-crossings-smooth sense-data 0 0 ))
37+ (check-equal? (stream-take-n crossings 6 ) '(0 0 0 -1 1 0 )))
38+ )
You can’t perform that action at this time.
0 commit comments