Skip to content

Instantly share code, notes, and snippets.

@johnmn3 johnmn3/uninterleave
Created Mar 28, 2011

Embed
What would you like to do?
the opposite of interleave
;;=> [0 1 0 1 0 1 0 1]
;; [[0 0 0 0] [1 1 1 1]]
(defn uninterleave
([asq] (unzip asq [] []))
([asq acum bcum]
(if (nil? (seq asq))
[acum bcum]
(recur (rest (rest asq)) (conj acum (first asq)) (conj bcum (first (rest asq)))))))
;; feel free to improve it
@johnmn3

This comment has been minimized.

Copy link
Owner Author

commented Mar 28, 2011

;; better

(defn uninterleave [asq]
[(take-nth 2 asq) (take-nth 2 (rest asq))])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.