summary refs log tree commit diff stats
path: root/go/hamming/hamming.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/hamming/hamming.go')
-rw-r--r--go/hamming/hamming.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/go/hamming/hamming.go b/go/hamming/hamming.go
new file mode 100644
index 0000000..a019855
--- /dev/null
+++ b/go/hamming/hamming.go
@@ -0,0 +1,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
+}