Skip to content

Instantly share code, notes, and snippets.

@hadielmougy
Last active August 31, 2016 22:34
Show Gist options
  • Save hadielmougy/c7106028513ede43f9444bedda954d17 to your computer and use it in GitHub Desktop.
Save hadielmougy/c7106028513ede43f9444bedda954d17 to your computer and use it in GitHub Desktop.
(defn longest [xs ys] (if (> (count xs) (count ys)) xs ys))
(def lcs
(memoize
(fn [[x & xs] [y & ys]]
(cond
(or (= x nil) (= y nil) ) nil
(= x y) (cons x (lcs xs ys))
:else (longest (lcs (cons x xs) ys) (lcs xs (cons y ys)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment