kris1511 has asked for the wisdom of the Perl Monks concerning the following question:
Where did I go wrong ? http://www.geeksforgeeks.org/dynamic-programming-set-5-edit-distance/sub editDistance{ my($str1, $str2, $len1, $len2) = @_; if ($len1 ==0){ return $len2; } if ($len2 ==0){ return $len1; } if(substr($str1, -1) eq substr($str2,-1)){ return editDistance($str1,$str2,$len1-1,$len2-1); } my @distance = (); push @distance, editDistance($str1, $str2, $len1, $len2-1); #inser +t push @distance, editDistance($str1, $str2, $len1-1, $len2); #remov +e push @distance, editDistance($str1, $str2, $len1-1, $len2-1); #rep +lace my $min = min @distance; return 1 + $min; } my $str1 ="Sundayyyy"; my $str2 = "Saturday"; print editDistance($str1, $str2, length($str1), length($str2))
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Edit Distance Implementation in Perl
by roboticus (Chancellor) on Aug 24, 2017 at 04:29 UTC | |
|
Re: Edit Distance Implementation in Perl
by thanos1983 (Parson) on Aug 24, 2017 at 09:29 UTC | |
by roboticus (Chancellor) on Aug 24, 2017 at 10:22 UTC | |
by thanos1983 (Parson) on Aug 24, 2017 at 10:29 UTC | |
|
Re: Edit Distance Implementation in Perl
by Laurent_R (Canon) on Aug 24, 2017 at 11:12 UTC | |
|
Re: Edit Distance Implementation in Perl
by tybalt89 (Monsignor) on Aug 24, 2017 at 12:48 UTC | |
|
Re: Edit Distance Implementation in Perl
by LanX (Saint) on Aug 23, 2017 at 23:35 UTC |