Created
June 21, 2019 16:49
-
-
Save lamdor/3f72dfd01c4d3f5f3062b585848dbbc4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hamming | |
import ( | |
"errors" | |
) | |
// Distance calculates the Hamming distance between two strings | |
func Distance(a, b string) (int, error) { | |
if len(a) != len(b) { | |
return 0, errors.New("Not same length") | |
} | |
var distance = 0 | |
brunes := []rune(b) | |
for i, achr := range a { | |
bchr := brunes[i] | |
if achr != bchr { | |
distance++ | |
} | |
} | |
return distance, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment