-
-
Save amalloy/1184193 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
(def levdist | |
(let [lev (atom nil) | |
impl | |
(fn [s t] | |
(let [lev @lev] | |
(cond | |
(empty? s) (count t) | |
(empty? t) (count s) | |
:else (let [ns (rest s) | |
nt (rest t)] | |
(if (= (first s) (first t)) | |
(lev ns nt) | |
(inc (min (lev s nt) | |
(lev ns t) | |
(lev ns nt))))))))] | |
(reset! lev (memoize impl)) | |
impl ;; or @lev, either one works! | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment