Created
August 31, 2011 15:47
-
-
Save jamesoly/1183870 to your computer and use it in GitHub Desktop.
Memoized version of 4clojure problem 101
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
(let [mem (atom {})] | |
(fn lev [s t] | |
(cond | |
(empty? s) (count t) | |
(empty? t) (count s) | |
:else (if-let [e (find @mem [s t])] | |
(val e) | |
(let [ns (rest s) | |
nt (rest t) | |
ret (if (= (first s) (first t)) | |
(lev ns nt) | |
(min (inc (lev s nt)) | |
(inc (lev ns t)) | |
(inc (lev ns nt))))] | |
(swap! mem assoc [s t] ret) | |
ret))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment