On Feb 3, 8:55 pm, braver wrote:
> Meikel -- cool lazy solution, but doesn't generalize to replace <=
> with a predicate. Here's my non-lazy, reduce-based one generic with
> instantiations:
>
> (defn clis-pred
> [pred s]
> (let [[x & xs] s [r zs _]
> (reduce (fn [[r zs z] e]
> (if (
Meikel -- cool lazy solution, but doesn't generalize to replace <=
with a predicate. Here's my non-lazy, reduce-based one generic with
instantiations:
(defn clis-pred
[pred s]
(let [[x & xs] s [r zs _]
(reduce (fn [[r zs z] e]
(if (pred z e) [r (conj zs e) e] [(conj r zs) [e] e]))
;; Ok, I'll try again using less columns...
(defn clis [coll]
(if (empty? coll) []
(loop [[head & tail] (rest coll)
streak [(first coll)]
output []]
(cond
(nil? head)
(conj output streak)
On Jan 28, 7:26 am, braver wrote:
> I'd like to partition a positive numeric sequence into subsequences so
> that each increasing subsequence is the longest possible among its
> neighbors. Here's the closest I got so far:
>
> (use 'clojure.contrib.seq-utils)
> (defn clis [s] (->> s (into [-1]) (p
Hi,
On Jan 28, 7:26 am, braver wrote:
> I'd like to partition a positive numeric sequence into subsequences so
> that each increasing subsequence is the longest possible among its
> neighbors. Here's the closest I got so far:
>
> (use 'clojure.contrib.seq-utils)
> (defn clis [s] (->> s (into [-1