Cody

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

Solution 1040817

Submitted on 31 Oct 2016 by Mohammad Haghighat
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   Pass

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

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

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

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

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

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

8   Pass

9   Pass
% 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

10   Pass
% 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