Skip to content

Instantly share code, notes, and snippets.

@erdos
Created June 6, 2017 17:01
Show Gist options
  • Save erdos/f6e2d91117facbf1ce0b95334be9d2e2 to your computer and use it in GitHub Desktop.
Save erdos/f6e2d91117facbf1ce0b95334be9d2e2 to your computer and use it in GitHub Desktop.
Longest Increasing Subsequence in Clojure
(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