No recursion needed, just nested ole point for loops
(defn subs [seq] (let [c (count seq)] (remove empty? (for [x (range c) y (range (- (inc c) x))] (take y (drop x seq))))))
and one more
(defn subs [seq] (letfn [(take-len [fs] (take (count s) (iterate fs)))] (mapcat #(reverse (take-len butlast %)) (take-len next seq))))
Just noticed that this is about the same as the eis version. I tried to collapse my own version of butlast (due to symmetry with the "iteration of the next"), but none of them made things shorter than nested for loops. Until I discovered that he stayed on clojuredocs.
In any case, try problems with 4clojure. The inability to get to the answers really makes you find the answer, any answer that works, and if you do / did, you will find it more elegant. And if you had no idea, usually the responses of other users will be highlighted or inspired after you allow it.
source share