Created
August 31, 2022 06:21
-
-
Save dexterous/25529839592fee9ef576aa462ed6657f to your computer and use it in GitHub Desktop.
Rotate a vector in Clojure
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 [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