Created
March 28, 2011 04:41
-
-
Save johnmn3/890019 to your computer and use it in GitHub Desktop.
the opposite of interleave
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
;;=> [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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
;; better
(defn uninterleave [asq]
[(take-nth 2 asq) (take-nth 2 (rest asq))])