Created
May 1, 2011 19:31
-
-
Save hans/950781 to your computer and use it in GitHub Desktop.
a function which will split a sequence into two parts
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
;; (split 3 [1 2 3 4 5 6]) => [[1 2 3] [4 5 6]] | |
;; (split 1 [:a :b :c :d]) => [[:a] [:b :c :d]] | |
(defn split [n xs] | |
(loop [acc '(), inacc '(), flxs (first xs), lxs (rest xs), cnt n] | |
(print acc inacc cnt "\n") | |
(if (nil? flxs) | |
(reverse (conj acc (reverse inacc))) | |
(if (zero? cnt) | |
(recur (conj acc (reverse inacc)) nil flxs lxs -1) | |
(recur acc (conj inacc flxs) (first lxs) (rest lxs) | |
(if (> cnt 0) (dec cnt) -1)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment