Skip to content

Instantly share code, notes, and snippets.

@jamesoly
Created August 31, 2011 15:47
Show Gist options
  • Save jamesoly/1183870 to your computer and use it in GitHub Desktop.
Save jamesoly/1183870 to your computer and use it in GitHub Desktop.
Memoized version of 4clojure problem 101
(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