Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-14 Thread Tyler Perkins
Here's what I came up with, a pretty functional approach: (fn [l] (let [lt(partial apply <) pairs (->> (map vector l (rest l)) (partition-by lt) (filter (comp lt first))) max-count (apply max 0 (map count pairs))] (->>

Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-13 Thread Yoshinori Kohyama
Hi Andy and all, Here's mine with trying to separate steps. You can see each steps with commenting out later steps. (fn [coll] (->> coll ; 1st. Make tails of coll. (#(take-while (comp not nil?) (iterate next %))) ; 2nd. Take only consecutive elements from the head for each

Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-13 Thread Andy Coolware
> > (defn lis [coll] >   (or (->> coll >            (partition-between (partial apply >=)) >            (sort-by (comp - count)) >            (filter next) >            (first)) >       [])) Totally agree on decomposing the problem into a single independent steps. This is what I did not like about

Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-13 Thread Alan Malloy
useful has a partition functionpowerful enough to make the "find increasing subsequences" part pretty easy: (defn lis [coll] (or (->> coll (partition-between (partial apply

Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-13 Thread Laurent PETIT
2012/6/12 Andy Coolware > Hi, > > First a quick disclaimer. Those are my first steps in Clojure so I am > not be super accustomed to the language entire landscape and might > miss some basics here. However I was able to solve my first 4clojure > hard problem https://www.4clojure.com/problem/53 and

Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-13 Thread JuanManuel Gimeno Illa
On Wednesday, June 13, 2012 5:47:55 PM UTC+2, Andy C wrote: > > On Wed, Jun 13, 2012 at 4:05 AM, JuanManuel Gimeno Illa wrote: > > My solution: > > > > (defn lis [s] > > (->> s > >(partition 2 1) > >(partition-by (partial apply <=)) > >(filter (fn [[[a b]]] (< a b)

Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-13 Thread Andy Coolware
On Wed, Jun 13, 2012 at 4:05 AM, JuanManuel Gimeno Illa wrote: > My solution: > > (defn lis [s] >   (->> s >        (partition 2 1) >        (partition-by (partial apply <=)) >        (filter (fn [[[a b]]] (< a b))) >        (reduce (fn [m s] (if (> (count s) (count m)) s m)) []) >        (#(cons

Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-13 Thread JuanManuel Gimeno Illa
My solution: (defn lis [s] (->> s (partition 2 1) (partition-by (partial apply <=)) (filter (fn [[[a b]]] (< a b))) (reduce (fn [m s] (if (> (count s) (count m)) s m)) []) (#(cons (ffirst %) (map second %) The strategy is (given the vector [3 2 1 2 4 2] -

Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-12 Thread Andy Coolware
forgot full listing: scala> List[Int](6, 7, 8, 1, 2, 3, 4, 1, 11, 10 ,11 ,12 ,13, | 3).foldLeft(List[List[Int]]()){(a,b)=> | if(a.isEmpty) List(List(b)) | else if(a.last.last < b) a.dropRight(1):::List(a.last:+b) | else a:::List(List(b)) | }.filter(_.

Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-12 Thread Andy Coolware
Nice. But I wonder if sorting and (count coll) actually forces the algorithm to load everything into memory. My Clojure solution is more convoluted (will post it later) and suffers the same due to a recursive algorithm doing the transformation I described at the end. However I think I have someth

Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-12 Thread Benny Tsai
This is what I ended up with, which I think is relatively clear and straightforward (but then, I'm not entirely unbiased :) The algorithm is very close to what you described. - Generate all sub-sequences of length > 1 - Filter to keep only increasing subsequences - Tack on the empty sequence, wh

so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-12 Thread Andy Coolware
Hi, First a quick disclaimer. Those are my first steps in Clojure so I am not be super accustomed to the language entire landscape and might miss some basics here. However I was able to solve my first 4clojure hard problem https://www.4clojure.com/problem/53 and have some second thoughts after loo