Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Bounty Awarded with 50 reputation awarded by Razetime
added 144 characters in body
Source Link
Leo
  • 12.9k
  • 1
  • 33
  • 63

Husk, 10(削除) 10 (削除ここまで) 9 bytes

L¤+Lṁ-→nṖ1Ṗ3→FnmṖ1

Try it online! Try it online!

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

Try it online!

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

Try it online!

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. (削除ここまで) Now I'm happy :)

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.

Source Link
Leo
  • 12.9k
  • 1
  • 33
  • 63

Husk, 10 bytes

L¤+-→nṖ1Ṗ3

Try it online!

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.

AltStyle によって変換されたページ (->オリジナル) /