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, which is what needs to be returned if there 
are no increasing sub-sequences
- Sort by length in descending order
- Take the first (longest)

(fn [coll]
   (let [increasing? (fn [xs] (apply < xs))
         n (count coll)
         sub-seqs (mapcat #(partition % 1 coll) (range 2 (inc n)))]
     (->> sub-seqs
          (filter increasing?)
          (cons [])
          (sort-by count >)
          first)))

On Tuesday, June 12, 2012 12:11:07 PM UTC-7, Andy C wrote:
>
> 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 looking up top contributor's solutions as well as mine. 
> Why it has to be so complicated??? 
>
> Conceptually, you just reduce the list to list of lists using a simple 
> condition < . Then you filter items longer then 1. And at the same 
> time you reduce the output to a first longest list. In this case, 
> stack for recursion is really not required, although I did use it in 
> my solution since I could figure out the "reduction" based way to 
> partition the source sequence. 
>
> It also seems that imperative solution would be quite straightforward 
> although maintaining at least 4 state variables is not compelling at 
> all. Bottom line, I want to have a idiomatic Clojure solution ... Any 
> insight .... 
>
> Thx, 
> Andy 
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to