mirror of
https://github.com/Egida/EndGame0.git
synced 2025-08-13 08:35:35 -04:00
EndGame v3
This commit is contained in:
commit
9e36ba54ee
646 changed files with 271674 additions and 0 deletions
25
sourcecode/gobalance/vendor/github.com/xrash/smetrics/hamming.go
generated
vendored
Normal file
25
sourcecode/gobalance/vendor/github.com/xrash/smetrics/hamming.go
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
package smetrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// The Hamming distance is the minimum number of substitutions required to change string A into string B. Both strings must have the same size. If the strings have different sizes, the function returns an error.
|
||||
func Hamming(a, b string) (int, error) {
|
||||
al := len(a)
|
||||
bl := len(b)
|
||||
|
||||
if al != bl {
|
||||
return -1, fmt.Errorf("strings are not equal (len(a)=%d, len(b)=%d)", al, bl)
|
||||
}
|
||||
|
||||
var difference = 0
|
||||
|
||||
for i := range a {
|
||||
if a[i] != b[i] {
|
||||
difference = difference + 1
|
||||
}
|
||||
}
|
||||
|
||||
return difference, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue