Skip to content

Instantly share code, notes, and snippets.

@dexterous
Created August 31, 2022 06:21
Show Gist options
  • Save dexterous/25529839592fee9ef576aa462ed6657f to your computer and use it in GitHub Desktop.
Save dexterous/25529839592fee9ef576aa462ed6657f to your computer and use it in GitHub Desktop.
Rotate a vector in Clojure
(defn rotate [v n]
(cond
(zero? n) v
(pos? n) (vec (concat (nthrest v n) (take n v)))
(neg? n) (rotate v (+ (count v) n))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment