22 lines
465 B
Go
22 lines
465 B
Go
|
package hamming
|
||
|
|
||
|
import "errors"
|
||
|
|
||
|
// TestVersion is an exercism thing
|
||
|
const TestVersion = 2
|
||
|
|
||
|
// Distance measures the hamming distance between two sequences
|
||
|
// and returns the number if different bytes and an error value
|
||
|
func Distance(seq1, seq2 string) (int, error) {
|
||
|
if len(seq1) != len(seq2) {
|
||
|
return -1, errors.New("Strands must be equal length")
|
||
|
}
|
||
|
var ret int
|
||
|
for i := 0; i < len(seq1); i++ {
|
||
|
if seq1[i] != seq2[i] {
|
||
|
ret++
|
||
|
}
|
||
|
}
|
||
|
return ret, nil
|
||
|
}
|