summary refs log blame commit diff stats
path: root/go/hamming/hamming.go
blob: a019855da25741993e67cd8e1b807c593f6581fe (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                             
// hamming implements Distance.
package hamming

import "errors"

// Distance returns the distance between 2 equal DNA strands.
func Distance(strand1, strand2 string) (int, error) {
	var dist int
	if len(strand1) != len(strand2) {
		return dist, errors.New("length not equal")
	}
	for idx := 0; idx < len(strand1); idx++ {
		if strand1[idx] != strand2[idx] {
			dist++
		}
	}
	return dist, nil
}