initial commit

This commit is contained in:
2021-08-08 21:11:22 +02:00
commit fe7136d801
130 changed files with 6858 additions and 0 deletions

41
c/hamming/src/hamming.c Normal file
View File

@@ -0,0 +1,41 @@
#include "hamming.h"
/* Note: For explanation on section below, see 'GNUfilename' included in
* link below :
* https://exercism.io/my/solutions/103b2f7d92db42309c1988030f5202c7
*/
#if defined UNIT_TEST || defined DEBUG
#include <stdio.h>
#include <stdlib.h>
#endif
/* test does not include invalid input, but it should, as the subject is
* about DNA sequence, not ASCII chars sequence :-)
* exercism test needs only:
* #define V(p) (*p)
*/
#define V(p) (*(p)=='A' || *(p)=='C' || *(p)=='G' || *(p)=='T')
int compute(const char *lhs, const char *rhs)
{
int res=0;
const char *l=lhs, *r=rhs;
if (!l || !r)
return -1;
for (; V(l) && V(r); ++l, ++r) {
if (*l != *r)
res++;
}
return *r || *l? -1: res;
}
#ifdef UNIT_TEST
int main(int ac, char **av)
{
if (ac==3) {
printf("compute(%s, %s)=%d\n", *(av+1), *(av+2), compute(*(av+1), *(av+2)));
}
}
#endif

15
c/hamming/src/hamming.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef HAMMING_H
#define HAMMING_H
int compute(const char *lhs, const char *rhs);
/* Note: For explanation on section below, see 'GNUfilename' included in
* link below :
* https://exercism.io/my/solutions/103b2f7d92db42309c1988030f5202c7
*/
#ifdef TESTALL
#undef TEST_IGNORE
#define TEST_IGNORE() {}
#endif
#endif