useful <https://github.com/flatland/useful> has a partition 
function<https://github.com/flatland/useful/blob/develop/src/useful/seq.clj#L222>powerful
 enough to make the "find increasing subsequences" part pretty easy:

(defn lis [coll]
  (or (->> coll
           (partition-between (partial apply >=))
           (sort-by (comp - count))
           (filter next)
           (first))
      []))

This isn't much shorter than your approach, but it makes every step easy to 
write and understand, and avoids doing any manual bookkeeping as in a 
reduce. It doesn't help for 4clojure, obviously, since you don't have 
partition-between available, but it underscores the importance of finding 
common patterns and lifting them out into their own functions with 
pluggable spots for the non-shared behavior.

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