|
1 | 1 | /*
|
2 | 2 | This algorithm calculates the distance between two strings.
|
3 |
| -Parameters: two strings to compare |
| 3 | +Parameters: two strings to compare and weights of insertion, substitution and deletion. |
4 | 4 | Output: distance between both strings
|
5 | 5 | */
|
6 | 6 |
|
@@ -59,8 +59,15 @@ func main() {
|
59 | 59 | str1 := "stingy"
|
60 | 60 | str2 := "ring"
|
61 | 61 |
|
62 |
| - strDistance := levenshteinDistance(str1, str2, 1, 1, 1) |
63 |
| - fmt.Printf("Distance between %s and %s is: %d.", str1, str2, strDistance) |
| 62 | + // Using weight 1 for insertion, substitution and deletion |
| 63 | + strDistance1 := levenshteinDistance(str1, str2, 1, 1, 1) |
| 64 | + fmt.Printf("Distance between \"%s\" and \"%s\" is: %d.\n", str1, str2, strDistance1) |
| 65 | + // Output: Distance between "stingy" and "ring" is: 3. |
| 66 | + |
| 67 | + // Using weight 1 for insertion/substitution and weight 3 for deletion |
| 68 | + strDistance2 := levenshteinDistance(str1, str2, 1, 1, 3) |
| 69 | + fmt.Printf("Distance between \"%s\" and \"%s\" is: %d.\n", str1, str2, strDistance2) |
| 70 | + // Output: Distance between "stingy" and "ring" is: 7. |
64 | 71 |
|
65 | 72 | return
|
66 | 73 | }
|
0 commit comments