]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex3_72.rkt
Solution to 4.30. Extremely enlightening!
[sicp.git] / src / sicp / ex3_72.rkt
1 #lang racket
2
3 (define (stream-triplicates s)
4   (if (= (stream-car s) (stream-car (stream-cdr s)) (stream-car (stream-cdr (stream-cdr s))))
5       (cons-stream (stream-car s)
6                    (stream-triplicates (stream-cdr (stream-cdr s))))
7       (stream-triplicates (stream-cdr s))))
8
9 (define (square-sum i j)
10   (+ (* i i) (* j j)))
11
12 (display-stream (stream-triplicates (stream-map (lambda (p) 
13                                                   (square-sum (car p) (car (cdr p))))
14                                                 (weighted-pairs integers integers square-sum))))
15
16 #|
17
18 325
19 425
20 650
21 725
22 845
23 850
24 925
25 1025
26 1105
27 1250
28 1300
29 1325
30 1445
31 1450
32 1525
33 1625
34 1690
35 1700
36 1825
37 1850
38 1885
39 2050
40 2125
41 2210
42 2225
43 2405
44 2425
45 2465
46 2525
47 2600
48 2650
49 2665
50
51 |#