exercism/go/hamming/hamming.go
2016-08-13 18:20:14 -05:00

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
}