Cody

# Problem 2309. Calculate the Damerau-Levenshtein distance between two strings.

Solution 1831278

Submitted on 30 May 2019
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail

Undefined function 'Damerau_Levenshtein' for input arguments of type 'char'. Error in Test1 (line 1) assert(isequal(Damerau_Levenshtein('mom','dad'),3));

2   Fail
assert(isequal(Damerau_Levenshtein('dogs','dog'),1)); % 1 deletion

Undefined function 'Damerau_Levenshtein' for input arguments of type 'char'. Error in Test2 (line 1) assert(isequal(Damerau_Levenshtein('dogs','dog'),1));

3   Fail
assert(isequal(Damerau_Levenshtein('true','true'),0)); % identity

Undefined function 'Damerau_Levenshtein' for input arguments of type 'char'. Error in Test3 (line 1) assert(isequal(Damerau_Levenshtein('true','true'),0));

4   Fail
assert(isequal(Damerau_Levenshtein('true','false'),4)); % 1 insertion, 3 substitutions

Undefined function 'Damerau_Levenshtein' for input arguments of type 'char'. Error in Test4 (line 1) assert(isequal(Damerau_Levenshtein('true','false'),4));

5   Fail
assert(isequal(Damerau_Levenshtein('abc','ca'),2)); % 1 deletion, 1 transposition

Undefined function 'Damerau_Levenshtein' for input arguments of type 'char'. Error in Test5 (line 1) assert(isequal(Damerau_Levenshtein('abc','ca'),2));

6   Fail
assert(isequal(Damerau_Levenshtein('tee','tree'),1));

Undefined function 'Damerau_Levenshtein' for input arguments of type 'char'. Error in Test6 (line 1) assert(isequal(Damerau_Levenshtein('tee','tree'),1));

7   Fail
assert(isequal(Damerau_Levenshtein('email','mails'),2));

Undefined function 'Damerau_Levenshtein' for input arguments of type 'char'. Error in Test7 (line 1) assert(isequal(Damerau_Levenshtein('email','mails'),2));

8   Fail

Undefined function 'Damerau_Levenshtein' for input arguments of type 'char'. Error in Test8 (line 1) assert(isequal(Damerau_Levenshtein('profit','gifts'),5));

9   Fail
% symmetry rnd=@()char(randi([97 122],1,randi([4 10]))); for k=1:10 str1=rnd(); str2=rnd(); a=Damerau_Levenshtein(str1,str2); b=Damerau_Levenshtein(str2,str1); assert(isequal(a,b)) end

Undefined function 'Damerau_Levenshtein' for input arguments of type 'char'. Error in Test9 (line 6) a=Damerau_Levenshtein(str1,str2);

10   Fail
% trinagle inequality rnd=@()char(randi([97 122],1,randi([4 10]))); for k=1:50 str1=rnd(); str2=rnd(); str3=rnd(); a=Damerau_Levenshtein(str2,str3); b=Damerau_Levenshtein(str3,str1); c=Damerau_Levenshtein(str1,str2); assert(a+b>=c) end

Undefined function 'Damerau_Levenshtein' for input arguments of type 'char'. Error in Test10 (line 7) a=Damerau_Levenshtein(str2,str3);