Files
PetroProtsyk-SSharp/Tests/Algorithms.EditDistance.sht
2019-06-15 11:37:21 +02:00

24 lines
818 B
Plaintext

function SerialEditDistance(s1, s2)
{
dist = new int[s1.Length + 1, s2.Length + 1];
for (i = 0; i <= s1.Length; i++) dist[i, 0] = i;
for (j = 0; j <= s2.Length; j++) dist[0, j] = j;
for (i = 1; i <= s1.Length; i++)
{
for (j = 1; j <= s2.Length; j++)
{
if (s1[i - 1] == s2[j - 1])
dist[i, j] = dist[i - 1, j - 1];
else
dist[i, j] = 1 + Math.Min(dist[i - 1, j],
Math.Min(dist[i, j - 1],
dist[i - 1, j - 1]));
}
}
return dist[s1.Length, s2.Length];
}
Test.AreEqual(4,SerialEditDistance('HELLO','WORLD'));