Husk, 10(削除) 10 (削除ここまで) 9 bytes
L¤+Lṁ-→nṖ1Ṗ3→FnmṖ1
Inspired by ais523's Brachylog solution, finds the longest common (not necessarily contiguous) subsequence and subtracts it from each string.
I don't like having to repeat Ṗ twice and having to explicitly refer to the two arguments(削除) I don't like having to repeat Ṗ twice and having to explicitly refer to the two arguments 1 and 3, but I couldn't find any shorter alternative. (削除ここまで)1 andNow I'm happy 3, but I couldn't find any shorter alternative.:)
Explanation
L¤+Lṁ-→nṖ1Ṗ3→FnmṖ1 Input: a list containing the two strings
Ṗ1Ṗ3 Ṗ Get all possible subsequences m 1 for each inputstring
n Fn and keepKeep only the common ones
→ Get the last one (which will be the longest)
- and subtract it
¤ṁ from each of the inputs
+ , then concatenate the remaining characters
L and findFind the length of this
Subtracting the longest common substring for each input results in the lists of characters that need to be deleted/inserted. We concatenate these two lists and get the length to calculate the edit distance.
Husk, 10 bytes
L¤+-→nṖ1Ṗ3
Inspired by ais523's Brachylog solution, finds the longest common (not necessarily contiguous) subsequence and subtracts it from each string.
I don't like having to repeat Ṗ twice and having to explicitly refer to the two arguments 1 and 3, but I couldn't find any shorter alternative.
Explanation
L¤+-→nṖ1Ṗ3
Ṗ1Ṗ3 Get all possible subsequences for each input
n and keep only the common ones
→ Get the last one (which will be the longest)
- and subtract it
¤ from each of the inputs
+ then concatenate the remaining characters
L and find the length of this
Subtracting the longest common substring for each input results in the lists of characters that need to be deleted/inserted. We concatenate these two lists and get the length to calculate the edit distance.
Husk, (削除) 10 (削除ここまで) 9 bytes
Lṁ-→FnmṖ1
Inspired by ais523's Brachylog solution, finds the longest common (not necessarily contiguous) subsequence and subtracts it from each string.
(削除) I don't like having to repeat Now I'm happy :)Ṗ twice and having to explicitly refer to the two arguments 1 and 3, but I couldn't find any shorter alternative. (削除ここまで)
Explanation
Lṁ-→FnmṖ1 Input: a list containing the two strings
Ṗ Get all possible subsequences m 1 for each string
Fn Keep only the common ones
→ Get the last one (which will be the longest)
- and subtract it
ṁ from each of the inputs, then concatenate the remaining characters
L Find the length of this
Subtracting the longest common substring for each input results in the lists of characters that need to be deleted/inserted. We concatenate these two lists and get the length to calculate the edit distance.
Husk, 10 bytes
L¤+-→nṖ1Ṗ3
Inspired by ais523's Brachylog solution, finds the longest common (not necessarily contiguous) subsequence and subtracts it from each string.
I don't like having to repeat Ṗ twice and having to explicitly refer to the two arguments 1 and 3, but I couldn't find any shorter alternative.
Explanation
L¤+-→nṖ1Ṗ3
Ṗ1Ṗ3 Get all possible subsequences for each input
n and keep only the common ones
→ Get the last one (which will be the longest)
- and subtract it
¤ from each of the inputs
+ then concatenate the remaining characters
L and find the length of this
Subtracting the longest common substring for each input results in the lists of characters that need to be deleted/inserted. We concatenate these two lists and get the length to calculate the edit distance.