File tree Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Original file line number Diff line number Diff line change 16
16
(define (square x)
17
17
(* x x))
18
18
19
- (define (pythagorean)
19
+ (define (pythagorean triple-stream )
20
20
(stream-filter (lambda (triple)
21
21
(= (+ (square (car triple))
22
22
(square (cadr triple)))
23
23
(square (caddr triple))))
24
- (triples integers integers integers) ))
24
+ triple-stream ))
25
25
(module+ test
26
26
(require rackunit)
27
27
28
28
(test-case "Test for triples "
29
29
(define s1 (list-to-stream '(1 2 3 )))
30
30
(define s2 (list-to-stream '(1 2 3 )))
31
31
(define s3 (list-to-stream '(1 2 3 )))
32
- (check-equal? (stream-to-list (triples s1 s2 s3) 10 ) '((1 1 1 ) (1 1 2 ) (2 2 2 ) (1 2 2 ) (2 2 3 )))
33
- )
34
- (test-case "Test for pythagorean "
35
- (check-equal? (stream-to-list (pythagorean) 2 ) '((3 4 5 ) (6 8 10 )))
36
- )
37
- )
32
+ (check-equal? (stream-to-list (triples s1 s2 s3) 20 ) '((1 1 1 )
33
+ (1 1 2 )
34
+ (2 2 2 )
35
+ (1 2 2 )
36
+ (2 2 3 )
37
+ (1 1 3 )
38
+ (3 3 3 )
39
+ (1 2 3 )
40
+ (2 3 3 )
41
+ (1 3 3 )))
42
+ (test-case "Test for pythagorean "
43
+ (define s1 (stream-enumerate-interval 1 10 ))
44
+ (define s2 (stream-enumerate-interval 1 10 ))
45
+ (define s3 (stream-enumerate-interval 1 10 ))
46
+ (check-equal? (stream-to-list (pythagorean (triples s1 s2 s3)) 2 ) '((3 4 5 ) (6 8 10 )))
47
+ )
48
+ ))
Original file line number Diff line number Diff line change 32
32
(define (interleave s1 s2)
33
33
(if (stream-null? s1)
34
34
s2
35
- (if (stream-null? s2)
36
- the-empty-stream
37
- (cons-stream (stream-car s1)
38
- (interleave s2 (stream-cdr s1))))))
35
+ (cons-stream (stream-car s1)
36
+ (interleave s2 (stream-cdr s1)))))
39
37
40
38
(define (pairs s t)
41
39
(if (or (stream-null? s) (stream-null? t))
You can’t perform that action at this time.
0 commit comments