Created
August 30, 2011 07:25
-
-
Save anonymous/1180380 to your computer and use it in GitHub Desktop.
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
;; amalloy's solution to Levenshtein Distance | |
;; https://4clojure.com/problem/101 | |
(letfn [(iters [n f start] | |
(take n (map second | |
(iterate f start))))] | |
(fn [s t] | |
(let [m (inc (count s)), n (inc (count t)) | |
first-row (vec (range m)) | |
matrix (iters n (fn [[j row]] | |
[(inc j) | |
(vec (iters m (fn [[i col]] | |
[(inc i) | |
(if (= (nth s i) | |
(nth t j)) | |
(get row i) | |
(inc (min (get row i) | |
(get row (inc i)) | |
col)))]) | |
[0 (inc j)]))]) | |
[0 first-row])] | |
(last (last matrix))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment