summary refs log tree commit diff stats
path: root/c/hamming/src
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-08-11 15:26:15 +0530
committerAndinus <andinus@nand.sh>2021-08-11 15:26:15 +0530
commit321825828ac918bad28d0597a8616c6dc9802c3c (patch)
tree0b8e9cb1012197750eb58e972736319b2a6abac2 /c/hamming/src
parent2979ef790ac5b8f58495e0dd08cafd6a3a2e30a5 (diff)
downloadexercism-321825828ac918bad28d0597a8616c6dc9802c3c.tar.gz
Add solved exercises
Diffstat (limited to 'c/hamming/src')
-rw-r--r--c/hamming/src/hamming.c12
-rw-r--r--c/hamming/src/hamming.h6
2 files changed, 18 insertions, 0 deletions
diff --git a/c/hamming/src/hamming.c b/c/hamming/src/hamming.c
new file mode 100644
index 0000000..f9651e0
--- /dev/null
+++ b/c/hamming/src/hamming.c
@@ -0,0 +1,12 @@
+#include <stdlib.h>
+#include "hamming.h"
+
+size_t compute(const char *lhs, const char *rhs) {
+    size_t diff = 0;
+    for (size_t idx = 0; ; idx++) {
+        short res = (lhs[idx] == '\0') + (rhs[idx] == '\0');
+        if (res == 1) return -1;
+        if (res == 2) return diff;
+        if (lhs[idx] != rhs[idx]) diff++;
+    }
+}
diff --git a/c/hamming/src/hamming.h b/c/hamming/src/hamming.h
new file mode 100644
index 0000000..18a1911
--- /dev/null
+++ b/c/hamming/src/hamming.h
@@ -0,0 +1,6 @@
+#ifndef HAMMING_H
+#define HAMMING_H
+
+size_t compute(const char *lhs, const char *rhs);
+
+#endif