Ver Mensaje Individual
  #2  
Antiguo 11-06-2010
cecam cecam is offline
Miembro
 
Registrado: may 2006
Ubicación: Girona
Posts: 47
Reputación: 0
cecam Va por buen camino
Hoooola!!

Si no me equivoco se llama Distancia_de_Levenshtein
http://es.wikipedia.org/wiki/Distancia_de_Levenshtein

Código:
function levenshtein(Str1, Str2: String): Integer;
var
  d : array of array of Integer;
  Len1, Len2 : Integer;
  i,j,cost:Integer;
begin
  Len1:=Length(Str1);
  Len2:=Length(Str2);
  SetLength(d,Len1+1);
  for i := Low(d) to High(d) do
      SetLength(d[i],Len2+1);

  for i := 0 to Len1 do
      d[i,0]:=i;

  for j := 0 to Len2 do
      d[0,j]:=j;

  for i:= 1 to Len1 do
    for j:= 1 to Len2 do begin
        if   Str1[i]=Str2[j]
        then cost:=0
        else cost:=1;
        d[i,j]:= Min(d[i-1, j] + 1,     // deletion,
                     Min(d[i, j-1] + 1, // insertion
                         d[i-1, j-1] + cost // substitution
                        )
                    );
    end;
  Result:=d[Len1,Len2];
end;
Saludos!!
Responder Con Cita