From: Ramakrishnan Muthukrishnan Date: Tue, 7 Sep 2010 10:55:56 +0000 (+0530) Subject: solution to 2.61 X-Git-Url: https://git.rkrishnan.org/pf/content/en/footer/%3C?a=commitdiff_plain;h=83f2c18927e5ab573d5b16c0befd340999e0f74b;p=sicp.git solution to 2.61 --- diff --git a/src/sicp/ex2_61.clj b/src/sicp/ex2_61.clj new file mode 100644 index 0000000..c897c61 --- /dev/null +++ b/src/sicp/ex2_61.clj @@ -0,0 +1,19 @@ +(ns sicp.ex2_61 + (:use [sicp.ex2_54 :only (equal? eq?)] + [clojure.test])) + +(defn adjoin-set [x set] + (let [x1 (first set)] + (cond (empty? set) (cons x set) + (= x x1) set + (< x x1) (cons x set) + (> x x1) (cons x1 (adjoin-set x (rest set)))))) + +(deftest test-adjoin + (are [x y] [= x y] + (adjoin-set 0 '()) '(0) + (adjoin-set 1 '(2 3)) '(1 2 3) + (adjoin-set 3 '(1 2 3)) '(1 2 3) + (adjoin-set 3 '(1 2 4)) '(1 2 3 4) + (adjoin-set 4 '(1 2 4)) '(1 2 4) + (adjoin-set 4 '(1 2 3)) '(1 2 3 4))) \ No newline at end of file