From: Ramakrishnan Muthukrishnan Date: Sun, 28 Mar 2010 12:59:22 +0000 (+0530) Subject: exercise 1.3 redone X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg//%22%22.?a=commitdiff_plain;h=6d677f3a4d7c3bc230f4bd93efac20536ecfa863;p=sicp.git exercise 1.3 redone --- diff --git a/chapter1/ch1_1.clj b/chapter1/ch1_1.clj index b96191b..783e139 100644 --- a/chapter1/ch1_1.clj +++ b/chapter1/ch1_1.clj @@ -56,6 +56,17 @@ (defn sum-of-sq-of-two-largest [a b c] (apply sum-of-squares (take 2 (sort3 a b c)))) +;; well, I cheated above. Let me use only the constructs introduced +;; so far in the book. (follows after the sicp meetup #2 on 28/mar/2010. +(defn sum-of-square-of-two-largest [a b c] + (if (> a b) + (if (> b c) + (sum-of-squares a b) ; a > b > c + (sum-of-squares a c)) + (if (> a c) + (sum-of-squares b a) + (sum-of-squares b c)))) + ;; exercise 1.4: Observe that our model of evaluation allows for ;; combinations whose operators are compound ;; expressions. Use this observation to describe the