(wat-aro)

無職から有職者にランクアップしました

SICP 問題 2.41

(define (equal-sum-of-unique-trio n s)
  (filter (lambda (l) (= s (+ (car l) (cadr l) (caddr l))))
          (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))))
gosh> (equal-sum-of-unique-trio 10 20)
((8 7 5) (9 6 5) (9 7 4) (9 8 3) (10 6 4) (10 7 3) (10 8 2) (10 9 1))