From 2326df1f37551eb856a8422ff52bc277306f9c9b Mon Sep 17 00:00:00 2001 From: David Kun Date: Tue, 6 Aug 2024 19:56:49 -0400 Subject: [PATCH] Add q39 --- src/ex/q039.clj | 11 +++++++++++ test/ex/q039_test.clj | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/ex/q039.clj create mode 100644 test/ex/q039_test.clj diff --git a/src/ex/q039.clj b/src/ex/q039.clj new file mode 100644 index 0000000..0ef7034 --- /dev/null +++ b/src/ex/q039.clj @@ -0,0 +1,11 @@ +;; https://4clojure.oxal.org/#/problem/039 + +(ns ex.q039) + +(defn ans + "Problem 39, Interleave Two Seqs. restriction: interleave" + [coll1 coll2] + (let [c1 (seq coll1) c2 (seq coll2)] + (if (and c1 c2) + (cons (first c1) (cons (first c2) (ans (rest c1) (rest c2)))) + []))) \ No newline at end of file diff --git a/test/ex/q039_test.clj b/test/ex/q039_test.clj new file mode 100644 index 0000000..c8594b9 --- /dev/null +++ b/test/ex/q039_test.clj @@ -0,0 +1,12 @@ +;; https://4clojure.oxal.org/#/problem/039 + +(ns ex.q039-test + (:require [clojure.test :as t] + [ex.q039 :as sut])) + +(t/deftest test-q39 + (t/testing "Problem 39, Interleave Two Seqs" + (t/is (= '(1 :a 2 :b 3 :c) (sut/ans [1 2 3] [:a :b :c]))) + (t/is (= '(1 3 2 4) (sut/ans [1 2] [3 4 5 6]))) + (t/is (= [1 5] (sut/ans [1 2 3 4] [5]))) + (t/is (= [30 25 20 15] (sut/ans [30 20] [25 15]))))) \ No newline at end of file