OFFSET
0,4
COMMENTS
a(n) = minimal number of editing steps (delete, insert or substitute) to transform 2^n into 2^(n+1) in decimal representation;
a(n) <= A034887(n).
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 0..1000
Michael Gilleland, Levenshtein Distance [It has been suggested that this algorithm gives incorrect results sometimes. - N. J. A. Sloane]
Haskell Wiki, Edit distance
WikiBooks: Algorithm Implementation, Levenshtein Distance
Wikipedia, Edit Distance
Wikipedia, Levenshtein Distance
MATHEMATICA
levenshtein[s_List, t_List] := Module[{d, n = Length@s, m = Length@t}, Which[s === t, 0, n == 0, m, m == 0, n, s != t, d = Table[0, {m + 1}, {n + 1}]; d[[1, Range[n + 1]]] = Range[0, n]; d[[Range[m + 1], 1]] = Range[0, m]; Do[ d[[j + 1, i + 1]] = Min[d[[j, i + 1]] + 1, d[[j + 1, i]] + 1, d[[j, i]] + If[ s[[i]] === t[[j]], 0, 1]], {j, m}, {i, n}]; d[[ -1, -1]] ]]; Table[ levenshtein[IntegerDigits[2^n], IntegerDigits[2^(n + 1)]], {n, 0, 80}] (* Robert G. Wilson v *)
PROG
(Haskell)
-- import Data.Function (on)
a106432 n = a106432_list !! n
a106432_list = zipWith (levenshtein `on` show)
a000079_list $ tail a000079_list where
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)]
-- Reinhard Zumkeller, Nov 10 2013
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Reinhard Zumkeller, Jan 22 2006
EXTENSIONS
More terms from Robert G. Wilson v, Jan 25 2006
STATUS
approved