Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

Levenshtein edit distance

Demo of the p/moul/x/daily/levenshtein library. The Levenshtein distance between two strings is the minimum number of single-character edits — insertions, deletions, or substitutions — needed to turn one string into the other. The library implements the classic dynamic-programming algorithm (à la Go's agext/levenshtein) fully rune-aware and on-chain.

Try it

Append two words as /<a>/<b>:

The classic example

kitten → sitting = 3:

  1. kitten → sitten (substitute k → s)
  2. sitten → sittin (substitute e → i)
  3. sittin → sitting (insert g at the end)

API

  • Distance(a, b string) int — the edit distance.
  • Matrix(a, b string) [][]int — the full DP matrix.
  • Similarity(a, b string) int — a 0..100 similarity percentage.