Created
September 3, 2011 11:31
-
-
Save prajwalit/1191042 to your computer and use it in GitHub Desktop.
[4clojure #44] Write a function which can rotate a sequence in either direction.
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
(defn rotate [n coll] | |
(let [[f s] (split-at (mod n (count coll)) coll)] | |
(concat s f))) | |
(rotate 2 [1 2 3 4 5]) | |
;; => (3 4 5 1 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(defn rotate
[n coll](let [m %28mod n %28count coll%29%29]
%28concat %28drop m coll%29 %28take m coll%29%29))