Skip to content

Instantly share code, notes, and snippets.

@Badgerati
Badgerati / levenshtein_algorithm.lua
Created August 5, 2012 02:09
An implementation of the Levenshtein distance algorithm in LUA.
-- Returns the Levenshtein distance between the two given strings
function string.levenshtein(str1, str2)
local len1 = string.len(str1)
local len2 = string.len(str2)
local matrix = {}
local cost = 0
-- quick cut-offs to save time
if (len1 == 0) then
return len2