Skip to content

Instantly share code, notes, and snippets.

@johnmn3
Created March 28, 2011 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmn3/890019 to your computer and use it in GitHub Desktop.
Save johnmn3/890019 to your computer and use it in GitHub Desktop.
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
Copy link
Author

johnmn3 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