-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))) | ||
[]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]))))) |