Last active
October 6, 2015 00:58
-
-
Save kohyama/e98d2c8a7b050765e20b to your computer and use it in GitHub Desktop.
Divide a sequence into continuous subsequences
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
(def sss | |
(memoize | |
(fn [s] | |
(let [n (count s)] | |
(cond | |
(zero? n) '(()) | |
(= n 1) `((~s)) | |
:else (mapcat | |
(fn [c] | |
(let [[a b] (split-at c s)] | |
(map #(cons a %) (lazy-seq (sss b))))) | |
(range 1 (inc n)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example to use