Created
June 6, 2017 17:01
-
-
Save erdos/f6e2d91117facbf1ce0b95334be9d2e2 to your computer and use it in GitHub Desktop.
Longest Increasing Subsequence in Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn filt [sequences] | |
(mapv (partial apply min-key peek) (vals (group-by count sequences)))) | |
(defn rfn [seqs x] | |
(filt (concat [[x]] seqs (for [cs seqs :when (> x (peek cs))] (conj cs x))))) | |
(defn longest-subseq [xs] | |
(apply max-key count [] (reduce rfn nil xs))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment