Created
November 22, 2014 01:15
-
-
Save noahmorrison/1fce5b0b98ff69c44270 to your computer and use it in GitHub Desktop.
Levenshtein distance in lisp (Recursive/slow)
This file contains 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
(defun leven-distance (string1 string2) | |
(if (= (length string1) 0) | |
(length string2) | |
(if (= (length string2) 0) | |
(length string1) | |
(min (+ (leven-distance (subseq string1 0 (- (length string1) 1)) | |
string2) | |
1) | |
(+ (leven-distance string1 | |
(subseq string2 0 (- (length string2) 1))) | |
1) | |
(+ (leven-distance (subseq string1 0 (- (length string1) 1)) | |
(subseq string2 0 (- (length string2) 1))) | |
(if (equal (subseq string1 (- (length string1) 1)) | |
(subseq string2 (- (length string2) 1))) | |
0 1)))))) | |
(defun get-string (prompt) | |
(format T prompt) | |
(read-line *query-io*)) | |
(defun main () | |
(format T "The diff is: ~a" | |
(leven-distance | |
(get-string "string1: ") | |
(get-string "string2: "))) | |
(quit)) | |
(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment