Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amalloy/1184193 to your computer and use it in GitHub Desktop.
Save amalloy/1184193 to your computer and use it in GitHub Desktop.
Memoized version of 4clojure problem 101
(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