From 3bba508f6af3423f20e044562183bc40f3cc5087 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Mon, 21 Jun 2010 19:39:57 +0530 Subject: [PATCH] solution to 2.20 --- src/sicp/ex2_20.clj | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/sicp/ex2_20.clj 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))) + -- 2.45.2