Wow, that was a very nice solution, even if it went far above and beyond the scope of the exercise in the book. Here is code for anyone here searching for a more concise solution:
(define (ordered-triples-sum n s) (filter (lambda (list) (= (accumulate + 0 list) s)) (flatmap (lambda (i) (flatmap (lambda (j) (map (lambda (k) (list i j k)) (enumerate-interval 1 (- j 1)))) (enumerate-interval 1 (- i 1)))) (enumerate-interval 1 n))))
If you are having a hard time understanding this problem, study the above implementation of build-tuples.
<< Previous exercise (2.40) | Index | Next exercise (2.42) >>