Skip to content

Commit

Permalink
Add q44
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkun committed Aug 11, 2024
1 parent 12da962 commit ed06eaa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ex/q044.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; https://4clojure.oxal.org/#/problem/044

(ns ex.q044)

(defn ans
"Problem 44, Rotate Sequence"
[x coll]
(let [len (count coll),
n (mod x len)]
(concat (drop n coll) (take n coll))))
13 changes: 13 additions & 0 deletions test/ex/q044_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;; https://4clojure.oxal.org/#/problem/044

(ns ex.q044-test
(:require [clojure.test :as t]
[ex.q044 :as sut]))

(t/deftest test-q44
(t/testing "Problem 44, Rotate Sequence"
(t/is (= '(3 4 5 1 2) (sut/ans 2 [1 2 3 4 5])))
(t/is (= '(4 5 1 2 3) (sut/ans -2 [1 2 3 4 5])))
(t/is (= '(2 3 4 5 1) (sut/ans 6 [1 2 3 4 5])))
(t/is (= '(:b :c :a) (sut/ans 1 '(:a :b :c))))
(t/is (= '(:c :a :b) (sut/ans -4 '(:a :b :c))))))

0 comments on commit ed06eaa

Please sign in to comment.