Skip to content

Instantly share code, notes, and snippets.

@Nondv
Last active April 18, 2017 21:26
Show Gist options
  • Select an option

  • Save Nondv/8f16b274b2e2eb8ecdc8782f25cde146 to your computer and use it in GitHub Desktop.

Select an option

Save Nondv/8f16b274b2e2eb8ecdc8782f25cde146 to your computer and use it in GitHub Desktop.
[4clojure.com] 44. Rotate sequence
; 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