Код Ревью
Сравни свои решения
(define (triples s t u)
(cons-stream
(list (stream-car s) (stream-car t) (stream-car u))
(interleave
(stream-map (lambda (x) (list (stream-car s) (car x) (cadr x)))
(pairs t (stream-cdr u)))
(triples (stream-cdr s) (stream-cdr t) (stream-cdr u)))))
#| correct version of triples, the codes above will not include (1 2 2), which should be included
(define (triples s t u)
(cons-stream
(list (stream-car s) (stream-car t) (stream-car u))
(interleave
(interleave
(stream-map (lambda (x) (list (stream-car s) (stream-car t) x))
(stream-cdr u))
(stream-map (lambda (x) (cons (stream-car s) x))
(pairs (stream-cdr t) (stream-cdr u))))
(triples (stream-cdr s) (stream-cdr t) (stream-cdr u)))))
|#
(define pythagorean-triples
(stream-filter
(lambda (x)
(let ((i (car x))
(j (cadr x))
(k (caddr x)))
(= (+ (square i) (square j)) (square k))))
(triples integers integers integers)))
(define (triples s t u)
(cons-stream
(list (stream-car s) (stream-car t) (stream-car u))
(interleave
(stream-map (lambda (x) (list (stream-car s) (car x) (cadr x)))
(pairs t (stream-cdr u)))
(triples (stream-cdr s) (stream-cdr t) (stream-cdr u)))))
(define pythagorean-triples
(stream-filter
(lambda (x)
(let ((i (car x))
(j (cadr x))
(k (caddr x)))
(= (+ (square i) (square j)) (square k))))
(triples integers integers integers)))
(define (triples s t u)
(cons-stream
(list (stream-car s) (stream-car t) (stream-car u))
(interleave
(stream-map (lambda (x) (list (stream-car s) (car x) (cadr x)))
(pairs t (stream-cdr u)))
(triples (stream-cdr s) (stream-cdr t) (stream-cdr u)))))
#| correct version of triples, the codes above will not include (1 2 2), which should be included
(define (triples s t u)
(cons-stream
(list (stream-car s) (stream-car t) (stream-car u))
(interleave
(stream-map (lambda (x) (cons (stream-car s) x))
(stream-cdr (pairs t u)))
(triples (stream-cdr s) (stream-cdr t) (stream-cdr u)))))
|#
(define pythagorean-triples
(stream-filter
(lambda (x)
(let ((i (car x))
(j (cadr x))
(k (caddr x)))
(= (+ (square i) (square j)) (square k))))
(triples integers integers integers)))
(define (triples s t u)
(cons-stream
(list (stream-car s) (stream-car t) (stream-car u))
(interleave
(stream-map (lambda (x) (list (stream-car s) (car x) (cadr x)))
(pairs t (stream-cdr u)))
(triples (stream-cdr s) (stream-cdr t) (stream-cdr u)))))
#| correct version of triples, the codes above will not include (1 2 2), which should be included
(define (triples s t u)
(cons-stream
(list (stream-car s) (stream-car t) (stream-car u))
(interleave
(interleave
(stream-map (lambda (x) (list (stream-car s) (stream-car t) x))
(stream-cdr u))
(stream-map (lambda (x) (cons (stream-car s) x))
(pairs (stream-cdr t) (stream-cdr u))))
(triples (stream-cdr s) (stream-cdr t) (stream-cdr u)))))
|#
(define pythagorean-triples
(stream-filter
(lambda (x)
(let ((i (car x))
(j (cadr x))
(k (caddr x)))
(= (+ (square i) (square j)) (square k))))
(triples integers integers integers)))
(define (triples s t u)
(cons-stream
(list (stream-car s) (stream-car t) (stream-car u))
(interleave
(stream-map (lambda (x) (list (stream-car s) (car x) (cadr x)))
(pairs t (stream-cdr u)))
(triples (stream-cdr s) (stream-cdr t) (stream-cdr u)))))
(define pythagorean-triples
(stream-filter
(lambda (x)
(let ((i (car x))
(j (cadr x))
(k (caddr x)))
(= (+ (square i) (square j)) (square k))))
(triples integers integers integers)))
(define (triples s t u)
(cons-stream
(list (stream-car s) (stream-car t) (stream-car u))
(interleave
(stream-map (lambda (x) (list (stream-car s) (car x) (cadr x)))
(pairs t (stream-cdr u)))
(triples (stream-cdr s) (stream-cdr t) (stream-cdr u)))))
#| correct version of triples, the codes above will not include (1 2 2), which should be included
(define (triples s t u)
(cons-stream
(list (stream-car s) (stream-car t) (stream-car u))
(interleave
(stream-map (lambda (x) (cons (stream-car s) x))
(stream-cdr (pairs t u)))
(triples (stream-cdr s) (stream-cdr t) (stream-cdr u)))))
|#
(define pythagorean-triples
(stream-filter
(lambda (x)
(let ((i (car x))
(j (cadr x))
(k (caddr x)))
(= (+ (square i) (square j)) (square k))))
(triples integers integers integers)))