From 45042a2683c74fc93bfa6e84aee1343da81a50b0 Mon Sep 17 00:00:00 2001 From: David Kun Date: Sat, 3 Aug 2024 12:56:54 -0400 Subject: [PATCH] Add q33 --- src/ex/q033.clj | 8 ++++++++ test/ex/q033_test.clj | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/ex/q033.clj create mode 100644 test/ex/q033_test.clj diff --git a/src/ex/q033.clj b/src/ex/q033.clj new file mode 100644 index 0000000..9077593 --- /dev/null +++ b/src/ex/q033.clj @@ -0,0 +1,8 @@ +;; https://4clojure.oxal.org/#/problem/033 + +(ns ex.q033) + +(defn ans + "Problem 33, Replicate a Sequence" + [coll n] + (reduce #(into %1 (repeat n %2)) [] coll)) \ No newline at end of file diff --git a/test/ex/q033_test.clj b/test/ex/q033_test.clj new file mode 100644 index 0000000..953eaaa --- /dev/null +++ b/test/ex/q033_test.clj @@ -0,0 +1,13 @@ +;; https://4clojure.oxal.org/#/problem/033 + +(ns ex.q033-test + (:require [clojure.test :as t] + [ex.q033 :as sut])) + +(t/deftest test-q33 + (t/testing "Problem 33, Replicate a Sequence" + (t/is (= '(1 1 2 2 3 3) (sut/ans [1 2 3] 2))) + (t/is (= '(:a :a :a :a :b :b :b :b) (sut/ans [:a :b] 4))) + (t/is (= '(4 5 6) (sut/ans [4 5 6] 1))) + (t/is (= '([1 2] [1 2] [3 4] [3 4]) (sut/ans [[1 2] [3 4]] 2))) + (t/is (= [44 44 33 33] (sut/ans [44 33] 2))))) \ No newline at end of file