OFFSET
1,3
LINKS
M. Gilleland, Levenshtein Distance. [It has been suggested that this algorithm gives incorrect results sometimes. - N. J. A. Sloane]
EXAMPLE
a(9)=8 since we can transform 9 into 9^9=387420489 by 8 insertions, namely inserting 3,8,7,4,2,0,4 and 8 in front of 9. a(2)=1 since we can transform 2 into 2^2=4 by one substitution, namely 4 for 2.
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]] ]];
f[n_] := levenshtein[IntegerDigits[n], IntegerDigits[n^n]]; Array[f, 69] (* Robert G. Wilson v *)
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Francois Jooste (pin(AT)myway.com), Mar 11 2003
EXTENSIONS
Corrected by Robert G. Wilson v, Jan 25 2006
STATUS
approved