summaryrefslogtreecommitdiff
path: root/go/hamming/hamming.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-08-25 03:13:39 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-08-25 03:13:39 +0200
commit509c5063d66e8bbef4ec1def1c99c318be51aceb (patch)
treeafc811c4781a4e317043e2a0237499defc168044 /go/hamming/hamming.go
Initial import
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..88dca1e
--- /dev/null
+++ b/go/hamming/hamming.go
@@ -0,0 +1,18 @@
+package hamming
+
+import "errors"
+
+const testVersion = 4
+
+func Distance(a, b string) (int, error) {
+ if len(a) != len(b) {
+ return 0, errors.New("same length required")
+ }
+ var n int
+ for i := 0; i < len(a); i++ {
+ if a[i] != b[i] {
+ n++
+ }
+ }
+ return n, nil
+}