Hey everyone,
I've had to code these guys up a few times:
(defn rotate
"Take a collection and left rotates it n steps. If n is negative,
the
collection is rotated right. Executes in O(n) time."
[n coll]
(let [c (count coll)]
(take c (drop (mod n c) (cycle coll)))))
(defn rotate-while
"Rotates a collection left while (pred item) is true. Will return a
unrotated
sequence if (pred item) is never true. Executes in O(n) time."
[pred coll]
(let [head (drop-while pred coll)]
(take (count coll) (concat head coll))))
Have other people had this problem?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en