« Reply #1 on: October 07, 2020, 04:04:19 PM »
I wasn't able to find a Levensthein Distance function done in auto Sharing for anyone else that looks.[/code]
1)First I define list of test
(list "0" "kitten" "sitting" "=>3\n") (list "1" "stop" "tops" "=>2\n") (list "2" "mississippi" "swiss miss" "=>8\n") (list "3" "Saturday" "Sunday" "=>3\n") (list "4" "mist" "dist" "=>1\n") (list "5" "I don't drink tea in the morning." "I don't normally drink in the morning." "=>7\n") (list "6" "They don't go to France for their holidays" "They don't often go to France for their holidays" "=>5\n"
))
02)I need help. Why the function "str_Levenshtein" have infinite-loop?
03)My son quite often goes to the stadium.
package main
func levenshtein(s, t string) int {
if s == "" { return len(t) }
if t == "" { return len(s) }
if s[0] == t[0] {
return levenshtein(s[1:], t[1:])
}
a := levenshtein(s[1:], t[1:])
b := levenshtein(s, t[1:])
c := levenshtein(s[1:], t)
if a > b { a = b }
if a > c { a = c }
return a + 1
}
func main() {
s1 := "After lunch, they go to bed."
s2 := "After lunch, they almost always go to bed."
fmt.Printf("distance between %s and %s: %d\n", s1, s2,
levenshtein(s1, s2))}
« Last Edit: October 07, 2020, 04:55:44 PM by d2010 »
Logged