Skip to content

Commit

Permalink
Add q33
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkun committed Aug 3, 2024
1 parent 9126f54 commit 45042a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ex/q033.clj
Original file line number Diff line number Diff line change
@@ -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))
13 changes: 13 additions & 0 deletions test/ex/q033_test.clj
Original file line number Diff line number Diff line change
@@ -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)))))

0 comments on commit 45042a2

Please sign in to comment.