Exercise 3-70 Original
Code
(Define (merge-weighted S1 s2 weight) (Cond ((stream-null s1) S2) ((stream-null S2) s1) (Else ( Let ((cars1 (stream-car s1)) (cars2 (stream-car S2) )) (Cond (< ( weight cars1 ) ( weight cars2 ) ( cons-stream cars1 (merge-weighted (stream-cdr s1) s2 weight)) ) ((= (weight cars1) (weight cars2)) (cons-stream cars1 (merge-weighted (stream-cdr s1) s2 weight ))) (else (cons-stream cars2 (merge-weighted s1 (stream-cdr S2) )) (weight))))))))(Define (weighted-pairs S1 s2 weight) (Cons-stream (list (stream-car s1) (stream-car S2)) (merge-weighted (stream-map (Lambda (x) ( list ( stream-car S1) x)(stream-cdr S2 ))( Weighted-pairs (stream-cdr s1) (stream-cdr S2) Weight) weight) ))(define weight1 (Lambda (x) ( + (car x) (cadr x) )))(define pairs1 (weighted-pairs integers integers weight1))(DefineWeight2(Lambda (x) ( + (* 2 (car x) ) (* 3 (cadr x)) (* 5 (car x) (cadr x) )))) (define ( Divide? X y) (= (remainder y x) 0 ) ) (define stream235 (stream-filter lambda (x ) ( not (or (divide? 2 x) divide? 3 x) divide? 5 x) ) ) ) integers) ) (define pairs2 (weighted-pairs stream235 stream235stream235 weight2))
"SICP Exercise" 139 Exercise 3.70