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]

- I get the sequence of consecutive pairs in the original vector
((3 2)(2 1)(1 2)(2 4)(4 2))
- I partition in sequences of pairs while the ordering criteria in a pair 
is maintained
(((3 2) (2 1))((1 2)(2 4))((4 2)))
- I filter out those with correspond to descendant subsequences
(((1 2)(2 4)))
- I get the maximun lenght sequene. I use reduce to compute it 
incrementally 
(((1 2)(2 4)))
- I reconstruct the sequence adjoint the first of the first pair with the 
seconds of each pair
(1 2 4)

Maybe there are some corner simplifications but I think it works

Juan Manuel

-- 
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