File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ ; ; https://4clojure.oxal.org/#/problem/053
2+
3+ (ns ex.q053 )
4+
5+ (defn ans
6+ " Problem 53, Longest Increasing Sub-Seq"
7+ [coll]
8+ (->> coll
9+ (partition 2 1 ) ; ; create overlapping pairs
10+ (partition-by #(= (inc (first %)) (second %))) ; ; partition by increasing pairs
11+ (filter #(= (inc (ffirst %)) (second (first %)))) ; ; drop violations
12+ (sort-by count)
13+ last ; ; grab longest sequence
14+ (reduce concat)
15+ dedupe)) ; ; remove overlapping elements
Original file line number Diff line number Diff line change 1+ ; ; https://4clojure.oxal.org/#/problem/053
2+
3+ (ns ex.q053-test
4+ (:require [clojure.test :as t]
5+ [ex.q053 :as sut]))
6+
7+ (t/deftest test-q53
8+ (t/testing " Problem 53, Longest Increasing Sub-Seq"
9+ (t/is (= [0 1 2 3 ] (sut/ans [1 0 1 2 3 0 4 5 ])))
10+ (t/is (= [5 6 ] (sut/ans [5 6 1 3 2 7 ])))
11+ (t/is (= [3 4 5 ] (sut/ans [2 3 3 4 5 ])))
12+ (t/is (= [] (sut/ans [7 6 5 4 ])))))
You can’t perform that action at this time.
0 commit comments