Created
January 24, 2018 11:46
-
-
Save omartell/e70f5301f2eb0e54c88a3887aab5f379 to your computer and use it in GitHub Desktop.
This file contains 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
(defn partition-2 | |
([n col] | |
(partition-2 n col [] [])) | |
([n col result current-partition] | |
(let [element (first col)] | |
(if (empty? col) | |
result | |
(recur n | |
(rest col) | |
(if (or (empty? (rest col)) (= (count current-partition) n)) | |
(conj result current-partition) | |
result) | |
(if (= (count current-partition) n) | |
[] | |
(conj current-partition element))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment