[go: up one dir, main page]

login
A248327
Levenshtein distance of n and its reversal in decimal representation, cf. A004086.
2
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 0, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 0, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 0, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 0, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 0, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 0, 2, 2, 1, 2, 2, 2, 2, 2
OFFSET
0,13
COMMENTS
a(n) = number of editing steps (replace, delete and insert) to transform n to A004086(n);
a(A002113(n)) = 0, a(10*A002113(n)) = 1 for n > 0;
a(A248336(n)) = n and a(m) != n for m < A248336(n).
LINKS
Haskell Wiki, Edit distance
WikiBooks: Algorithm Implementation, Levenshtein distance
PROG
(Haskell)
a248327 0 = 0
a248327 n = levenshtein (show n) (dropWhile (== '0') $ reverse $ show n)
levenshtein :: (Eq t) => [t] -> [t] -> Int
levenshtein us vs = last $ foldl transform [0..length us] vs where
transform xs@(x:xs') c = scanl compute (x+1) (zip3 us xs xs') where
compute z (c', x, y) = minimum [y+1, z+1, x + fromEnum (c' /= c)]
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Reinhard Zumkeller, Oct 05 2014
STATUS
approved