Last active
April 18, 2017 21:26
-
-
Save Nondv/8f16b274b2e2eb8ecdc8782f25cde146 to your computer and use it in GitHub Desktop.
[4clojure.com] 44. Rotate sequence
This file contains hidden or 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
| ; Write a function which can rotate a sequence in either direction. | |
| ; | |
| ; (= (__ 2 [1 2 3 4 5]) '(3 4 5 1 2)) | |
| ; (= (__ -2 [1 2 3 4 5]) '(4 5 1 2 3)) | |
| ; (= (__ 6 [1 2 3 4 5]) '(2 3 4 5 1)) | |
| ; (= (__ 1 '(:a :b :c)) '(:b :c :a)) | |
| ; (= (__ -4 '(:a :b :c)) '(:c :a :b)) | |
| ; (= (__ -4 '(:a :b :c)) '(:c :a :b)) | |
| #(let [r (mod %1 (count %2))] (flatten [(drop r %2) (take r %2)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment