Skip to content

Instantly share code, notes, and snippets.

@omartell
Created January 24, 2018 11:46
Show Gist options
  • Save omartell/e70f5301f2eb0e54c88a3887aab5f379 to your computer and use it in GitHub Desktop.
Save omartell/e70f5301f2eb0e54c88a3887aab5f379 to your computer and use it in GitHub Desktop.
(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