From: Ramakrishnan Muthukrishnan Date: Wed, 11 Aug 2010 14:57:43 +0000 (+0530) Subject: solution to 2.41 X-Git-Url: https://git.rkrishnan.org/pf/content/en/service/simplejson/configuration.txt?a=commitdiff_plain;h=84a9387597aac93c06f02990b8a68d5e93ae75c9;p=sicp.git solution to 2.41 --- diff --git a/src/sicp/ex2_41.clj b/src/sicp/ex2_41.clj new file mode 100644 index 0000000..e43773a --- /dev/null +++ b/src/sicp/ex2_41.clj @@ -0,0 +1,21 @@ +(ns sicp.ex2_41 + (:use [sicp.ch2-2 :only (enumerate-interval accumulate append)])) + +(defn triplets [n] + (accumulate append + nil + (accumulate append + nil + (map (fn [i] + (map (fn [j] + (map (fn [k] (list i j k)) + (enumerate-interval 1 (- j 1)))) + (enumerate-interval 1 (- i 1)))) + (enumerate-interval 1 n))))) + +(defn sum-triplets [triplet] + (accumulate + 0 triplet)) + +(defn ordered-triplets [n sum] + (filter #(= (sum-triplets %) sum) + (triplets n))) \ No newline at end of file