Skip to content

Instantly share code, notes, and snippets.

@prajwalit
Created September 3, 2011 11:31
Show Gist options
  • Save prajwalit/1191042 to your computer and use it in GitHub Desktop.
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.
(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)
@nipra
Copy link

nipra commented Sep 3, 2011

(defn rotate
[n coll](let [m %28mod n %28count coll%29%29]
%28concat %28drop m coll%29 %28take m coll%29%29))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment