edit distance - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# edit distance

Posts: 4Member
Could anyone write this code in mathematica [b]without[/b] using the [b]built-in[/b] function? I would be grateful..

main(){
char s[300],t[300];
int i,j,c,m,n,edit;
int a[301][301];

printf("give s: ");
scanf("%s",s);
printf("give t: ");
scanf("%s",t);
m=strlen(s);
n=strlen(t);

else{

for(i=0;i<=m;i++){
a[i][0]=i; }
for(j=1;j<=n;j++){
a[0][j]=j; }
for(i=1;i<=m;i++){
for(j=1;j<=n;j++){
if(s[i-1]==t[j-1])
c=0;
else c=1;

a[i][j]=min(a[i-1][j]+1,min(a[i][j-1]+1,a[i-1][j-1]+c));
edit=a[i][j];

}
}

}

}

## Comments

• Posts: 6,349Member
: Could anyone write this code in mathematica [b]without[/b] using the
: [b]built-in[/b] function? I would be grateful..
:
: main(){
: char s[300],t[300];
: int i,j,c,m,n,edit;
: int a[301][301];
:
:
: printf("give s: ");
: scanf("%s",s);
: printf("give t: ");
: scanf("%s",t);
: m=strlen(s);
: n=strlen(t);
:
:
: else{
:
:
:
:
: for(i=0;i<=m;i++){
: a[i][0]=i; }
: for(j=1;j<=n;j++){
: a[0][j]=j; }
: for(i=1;i<=m;i++){
: for(j=1;j<=n;j++){
: if(s[i-1]==t[j-1])
: c=0;
: else c=1;
:
: a[i][j]=min(a[i-1][j]+1,min(a[i][j-1]+1,a[i-1][j-1]+c));
: edit=a[i][j];
:
: }
: }
:
:
: }
:
: }
:
What's it intended to do? What's the error?
• Posts: 4Member
: : Could anyone write this code in mathematica [b]without[/b] using the
: : [b]built-in[/b] function? I would be grateful..
: :
: : main(){
: : char s[300],t[300];
: : int i,j,c,m,n,edit;
: : int a[301][301];
: :
: :
: : printf("give s: ");
: : scanf("%s",s);
: : printf("give t: ");
: : scanf("%s",t);
: : m=strlen(s);
: : n=strlen(t);
: :
: :
: : else{
: :
: :
: :
: :
: : for(i=0;i<=m;i++){
: : a[i][0]=i; }
: : for(j=1;j<=n;j++){
: : a[0][j]=j; }
: : for(i=1;i<=m;i++){
: : for(j=1;j<=n;j++){
: : if(s[i-1]==t[j-1])
: : c=0;
: : else c=1;
: :
: : a[i][j]=min(a[i-1][j]+1,min(a[i][j-1]+1,a[i-1][j-1]+c));
: : edit=a[i][j];
: :
: : }
: : }
: :
: :
: : }
: :
: : }
: :
: it computes the edit(levenshtein) distance between two strings.
i can't write this code in mathematica without using the built-in function

Sign In or Register to comment.