From 509c5063d66e8bbef4ec1def1c99c318be51aceb Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 25 Aug 2016 03:13:39 +0200 Subject: Initial import --- go/hamming/hamming.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 go/hamming/hamming.go (limited to 'go/hamming/hamming.go') 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 +} -- cgit v1.2.3