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)) |
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
;; joly's solution to Levenshtein Distance | |
;; https://4clojure.com/problem/101 | |
;; Slow, but finishes fast enough for test problems. | |
;; None of the self-memoized versions worked without | |
;; using def, but memoizing this version gave a | |
;; speedup from 2500 msec -> 10 msec. | |
(fn lev [s t] | |
(cond |