Skip to content

Instantly share code, notes, and snippets.

@hyone
Created June 18, 2011 10:47
Show Gist options
  • Save hyone/1032985 to your computer and use it in GitHub Desktop.
Save hyone/1032985 to your computer and use it in GitHub Desktop.
4clojure #53 - Longest continuous increasing subsequence
;; hyone's solution to Longest Increasing Sub-Seq
;; https://4clojure.com/problem/53
(fn longest-inc-seq [coll]
(reduce #(let [len-a (count %1)
len-b (count %2)]
(if (and (> len-b 1) (> len-b len-a)) %2 %1))
[]
(reductions
(fn [xs y]
(if (> y (last xs)) (conj xs y) [y]))
[(first coll)]
(rest coll))))
@leontalbot
Copy link

Cool! Here is mine.

(fn [coll] 
  (let [a (partition-by #(< (first %) (last %)) (partition 2 1 coll))
        b (filter #(< (ffirst %) (second (first %))) a)
        c (reduce #(if (< (count %1) (count %2)) %2 %1) [] b)] 
   (concat (first c) (map last (rest c)))))

@leontalbot
Copy link

(fn [coll] 
  (let [a (partition-by #(apply < %) (partition 2 1 coll))
        b (filter (fn [[[x1 x2]]] (< x1 x2)) a)
        c (first (sort-by count > b))] 
   (concat (first c) (map last (rest c)))))

@blambin
Copy link

blambin commented Apr 29, 2018

lonest of mine . :

(fn [coll]  
	(let [group-coll-index (fn [coll] (partition-by #(take-last 1 %) 
			(partition 2 
				(interleave coll 
					(flatten 
						(partition-by identity 
							(map + coll (iterate dec 0))) 
						))))) 
		  ] 
		  (if (>= (apply max (map count (group-coll-index coll))) 2) 
		  	(flatten (map butlast (last (sort-by count (group-coll-index coll)))))
		  	[])
		  )	
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment