mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-11-13 23:00:47 -05:00
22 lines
364 B
C
22 lines
364 B
C
#include "hamming.h"
|
|
#include <string.h>
|
|
|
|
int compute(const char *lhs, const char *rhs) {
|
|
size_t lhsLen = strlen(lhs);
|
|
size_t rhsLen = strlen(rhs);
|
|
|
|
if (lhsLen != rhsLen)
|
|
return -1;
|
|
|
|
if (lhsLen == 0 && rhsLen == 0)
|
|
return 0;
|
|
|
|
int count = 0;
|
|
|
|
for (size_t i = 0; i < lhsLen; ++i) {
|
|
if (lhs[i] != rhs[i])
|
|
count++;
|
|
}
|
|
|
|
return count;
|
|
}
|