Last active
September 25, 2015 11:48
-
-
Save stathissideris/916746 to your computer and use it in GitHub Desktop.
optimisation
This file contains 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 lcs [xr yr] | |
((fn inner-lcs [x y] | |
(cond | |
(or (zero? (count x)) (zero? (count y))) nil | |
(= (first x) (first y)) (cons (first x) (inner-lcs (rest x) (rest y))) | |
:else (let [xx (inner-lcs (rest x) y) | |
yy (inner-lcs x (rest y))] | |
(if (> (count xx) (count yy)) xx yy)))) xr yr)) | |
> (print "result:" (lcs "Stathis Georgiou Sideris" "Stathis Sideris") "\n") | |
result: (S t a t h i s S i d e r i s) | |
> (print "list result:" (prn-str (lcs [1 2 3 4 5 6 7] [-1 -2 3 4 7 8 9]))) | |
list result: (3 4 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Executes in 13% of the previous time