Skip to content

Commit

Permalink
Add q39
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkun committed Aug 6, 2024
1 parent 0e0ba02 commit 2326df1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ex/q039.clj
Original file line number Diff line number Diff line change
@@ -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))))
[])))
12 changes: 12 additions & 0 deletions test/ex/q039_test.clj
Original file line number Diff line number Diff line change
@@ -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])))))

0 comments on commit 2326df1

Please sign in to comment.