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 Revisions

2 of 2
added 144 characters in body
Leo
  • 12.9k
  • 1
  • 33
  • 63

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.

Leo
  • 12.9k
  • 1
  • 33
  • 63

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