From: Ramakrishnan Muthukrishnan Date: Mon, 21 Jun 2010 14:09:57 +0000 (+0530) Subject: solution to 2.20 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/index.php?a=commitdiff_plain;h=3bba508f6af3423f20e044562183bc40f3cc5087;p=sicp.git solution to 2.20 --- diff --git a/src/sicp/ex2_20.clj b/src/sicp/ex2_20.clj new file mode 100644 index 0000000..24b5f5e --- /dev/null +++ b/src/sicp/ex2_20.clj @@ -0,0 +1,16 @@ +(ns sicp.ex2_20 + (:use [clojure test] + [sicp utils])) +;; clojure has a slightly different notation compared to Scheme for the +;; arbitraty number of argument notation. +(defn same-parity [x & xs] + (cons x (filter (fn [y] (if (even? x) + (even? y) + (odd? y))) + xs))) + +(deftest test-same-parity + (are [x y] [= x y] + (same-parity 1 2 3 4 5 6 7) (list 1 3 5 7) + (same-parity 2 3 4 5 6 7) (list 2 4 6))) +