ludus

Levenshtein Distance

ld-0011 · 8 › ████████░░ · text, algorithms · requires: arrays, lambda, algorithmic · oner generalized golfed

Your client is a linguist with two lists of words, who wants to compare them to see how different each entry is from its counterpart.

The metric is Levenshtein Distance: the minimum number of single-character edits needed to turn one word into the other, where an edit removes a character, adds a character, or replaces a character. For example, "kitten" and "sitting" have a distance of 3: substitute k with s, substitute e with i, add g.

Produce the distance for each word pair, one row per input row. Words are lowercase and non-empty. The grader swaps in word lists of different lengths, so cover the whole OUTPUT range: empty input rows must produce empty output rows.

Work on it

  1. Make a copy of the template — it becomes your private sheet.
  2. Solve it however you like — helper columns and extra tabs are fair game. The one rule: the grader swaps INPUT for other datasets, so never put your own content inside INPUT.
  3. Check yourself against the expected sample output shown in your copy (and below).
  4. Submit below — Share → "anyone with the link, Viewer", paste the link. Your sheet is graded against 2 hidden datasets, so hardcoded answers won't survive.

Sample

Input (Input!B2:C18)

Word 1Word 2
kittensitting
saturdaysunday
flawlawn
samesame
abcxyz
bookback

Expected output (Answer!B3:B18)

Distance
3
3
2
0
3
2

Adapted from "Levenshtein Distance" in the astral.cafe Community Practice Problems sheet.