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 1616(define (square x)
1717 (* x x))
1818
19- (define (pythagorean)
19+ (define (pythagorean triple-stream )
2020 (stream-filter (lambda (triple)
2121 (= (+ (square (car triple))
2222 (square (cadr triple)))
2323 (square (caddr triple))))
24- (triples integers integers integers) ))
24+ triple-stream ))
2525(module+ test
2626 (require rackunit)
2727
2828 (test-case "Test for triples "
2929 (define s1 (list-to-stream '(1 2 3 )))
3030 (define s2 (list-to-stream '(1 2 3 )))
3131 (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 3232(define (interleave s1 s2)
3333 (if (stream-null? s1)
3434 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)))))
3937
4038(define (pairs s t)
4139 (if (or (stream-null? s) (stream-null? t))
You can’t perform that action at this time.
0 commit comments