Skip to content

Instantly share code, notes, and snippets.

@kohyama
Last active October 6, 2015 00:58
Show Gist options
  • Save kohyama/e98d2c8a7b050765e20b to your computer and use it in GitHub Desktop.
Save kohyama/e98d2c8a7b050765e20b to your computer and use it in GitHub Desktop.

Revisions

  1. kohyama revised this gist Oct 6, 2015. No changes.
  2. kohyama created this gist Oct 6, 2015.
    12 changes: 12 additions & 0 deletions subseqseq.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    (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))))))))