mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-12-22 14:43:10 -05:00
23 lines
364 B
C
23 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;
|
||
|
}
|