]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex2_20.clj
solution to 2.20
[sicp.git] / src / sicp / ex2_20.clj
1 (ns sicp.ex2_20
2   (:use [clojure test]
3         [sicp utils]))
4 ;; clojure has a slightly different notation compared to Scheme for the
5 ;; arbitraty number of argument notation.
6 (defn same-parity [x & xs]
7   (cons x (filter (fn [y] (if (even? x)
8                             (even? y)
9                             (odd? y)))
10                   xs)))
11
12 (deftest test-same-parity
13   (are [x y] [= x y]
14        (same-parity 1 2 3 4 5 6 7) (list 1 3 5 7)
15        (same-parity 2 3 4 5 6 7) (list 2 4 6)))
16