Skip to content

Instantly share code, notes, and snippets.

@mrBliss
Created September 20, 2010 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrBliss/588542 to your computer and use it in GitHub Desktop.
Save mrBliss/588542 to your computer and use it in GitHub Desktop.
(defn longest-equal-subseq-for
"Returns the longest subsequence of indices for which the following
statement is true:
for all i, j in subsequence: (f i) = (f j) != nil
If there are subsequences of equal size, the last one is returned."
[f indices]
(let [subseqs (remove (comp nil? first) (partition-by f indices))]
(if (seq subseqs)
(apply (partial max-key count) subseqs)
subseqs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment