Added free() calls
parent
6dd2ca300c
commit
eba796a33d
|
@ -35,36 +35,6 @@ uint32_t rmdups(signature * arr, uint32_t nitems) {
|
||||||
return nitems;
|
return nitems;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printDashed(uint32_t n) {
|
|
||||||
for (uint32_t i = A_BIT; i < Z_BIT; i <<= 1) {
|
|
||||||
if (i & n) {
|
|
||||||
char c = 'A';
|
|
||||||
uint32_t icopy = A_BIT;
|
|
||||||
while (icopy < i) {
|
|
||||||
c++;
|
|
||||||
icopy <<=1 ;
|
|
||||||
}
|
|
||||||
putchar(c);
|
|
||||||
} else {
|
|
||||||
putchar('-');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void printsigs(signature* sigs, uint32_t nitems, ...) {
|
|
||||||
va_list args;
|
|
||||||
va_start(args, nitems);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < nitems; i++) {
|
|
||||||
uint32_t index = va_arg(args, uint32_t);
|
|
||||||
signature s = sigs[index];
|
|
||||||
printDashed(s.sign);
|
|
||||||
printf(": %s : %04d\n", s.word, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
signature* makeArray(FILE * f, uint32_t* arrlen) {
|
signature* makeArray(FILE * f, uint32_t* arrlen) {
|
||||||
signature* sigs = (signature*) calloc(WORDS, sizeof(signature));
|
signature* sigs = (signature*) calloc(WORDS, sizeof(signature));
|
||||||
char word[WORDLEN + sizeof(char)]; // 5 letters + \n
|
char word[WORDLEN + sizeof(char)]; // 5 letters + \n
|
||||||
|
@ -86,4 +56,35 @@ signature* makeArray(FILE * f, uint32_t* arrlen) {
|
||||||
|
|
||||||
*arrlen = i;
|
*arrlen = i;
|
||||||
return sigs;
|
return sigs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printDashed(uint32_t n) {
|
||||||
|
for (uint32_t i = A_BIT; i < Z_BIT; i <<= 1) {
|
||||||
|
if (i & n) {
|
||||||
|
char c = 'A';
|
||||||
|
uint32_t bit = A_BIT;
|
||||||
|
while (bit < i) {
|
||||||
|
c++;
|
||||||
|
bit <<= 1;
|
||||||
|
}
|
||||||
|
putchar(c);
|
||||||
|
} else {
|
||||||
|
putchar('-');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void printsigs(signature* sigs, uint32_t nitems, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, nitems);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < nitems; i++) {
|
||||||
|
uint32_t index = va_arg(args, uint32_t);
|
||||||
|
signature s = sigs[index];
|
||||||
|
printDashed(s.sign);
|
||||||
|
printf(": %s : %-4d\n", s.word, index);
|
||||||
|
}
|
||||||
|
putchar('\n');
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
}
|
}
|
|
@ -40,9 +40,15 @@ uint32_t rawWC = 0;
|
||||||
|
|
||||||
|
|
||||||
#if PRINT_INTERMEDIATES
|
#if PRINT_INTERMEDIATES
|
||||||
#define PRINT2 printsigs(sigs, 2, i1, i2);
|
#if FANCYPRINT
|
||||||
#define PRINT3 printsigs(sigs, 3, i1, i2, i3);
|
#define PRINT2 printsigs(sigs, 2, i1, i2);
|
||||||
#define PRINT4 printsigs(sigs, 4, i1, i2, i3, i4);
|
#define PRINT3 printsigs(sigs, 3, i1, i2, i3);
|
||||||
|
#define PRINT4 printsigs(sigs, 4, i1, i2, i3, i4);
|
||||||
|
#else
|
||||||
|
#define PRINT2 printf("%s, %s\n", sigs[i1], sigs[i2]);
|
||||||
|
#define PRINT3 printf("%s, %s, %s\n", sigs[i1], sigs[i2], sigs[i3]);
|
||||||
|
#define PRINT4 printf("%s, %s, %s, %s\n", sigs[i1], sigs[i2], sigs[i3], sigs[i4]);
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#define PRINT2 0;
|
#define PRINT2 0;
|
||||||
#define PRINT3 0;
|
#define PRINT3 0;
|
||||||
|
|
44
solvedle.c
44
solvedle.c
|
@ -55,45 +55,71 @@ int main(int argc, char * argv[]) {
|
||||||
#if PRINT_INTERMEDIATES
|
#if PRINT_INTERMEDIATES
|
||||||
fprintf(stderr, "INTERMEDIATE: ended with %u totally unique words\n", cookedWC);
|
fprintf(stderr, "INTERMEDIATE: ended with %u totally unique words\n", cookedWC);
|
||||||
#endif
|
#endif
|
||||||
START_TIME("finding words")
|
|
||||||
findWords(sigs, cookedWC);
|
findWords(sigs, cookedWC);
|
||||||
END_TIME
|
|
||||||
|
|
||||||
#if TIME_SECTIONS
|
#if TIME_SECTIONS
|
||||||
clock_t prog_end = clock();
|
clock_t prog_end = clock();
|
||||||
fprintf(stderr, "%s took %fs total\n", argv[0], ((double)(prog_end - prog_start)) / CLOCKS_PER_SEC);
|
fprintf(stderr, "%s took %fs total\n", argv[0], ((double)(prog_end - prog_start)) / CLOCKS_PER_SEC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if FREE
|
||||||
|
for (uint32_t i = 0; i < fiveUniqWC; i++) {
|
||||||
|
free(sigs[i].word);
|
||||||
|
}
|
||||||
|
free(sigs);
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void findWords(signature* sigs, uint32_t len) {
|
void findWords(signature* sigs, uint32_t len) {
|
||||||
|
START_TIME("finding starts")
|
||||||
|
// for each index, locate the first index of
|
||||||
|
// a word that shares no letters with it, and
|
||||||
|
// store the distance between the two.
|
||||||
|
uint32_t * starts = calloc(len, sizeof(uint32_t));
|
||||||
|
for (uint32_t i = 0, j = 0; i < len && j < len; i++) {
|
||||||
|
uint32_t sig = sigs[i].sign;
|
||||||
|
for (j = i+1; j < len; j++) {
|
||||||
|
if ((sig & sigs[j].sign) == 0) {
|
||||||
|
starts[i] = j - i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
END_TIME
|
||||||
|
|
||||||
|
START_TIME("finding words")
|
||||||
|
// the big loop.
|
||||||
for (uint32_t i1 = 0; i1 < len; i1++) {
|
for (uint32_t i1 = 0; i1 < len; i1++) {
|
||||||
uint32_t a = sigs[i1].sign;
|
uint32_t a = sigs[i1].sign;
|
||||||
|
|
||||||
for (uint32_t i2 = i1+1; i2 < len; i2++) {
|
for (uint32_t i2 = starts[i1]+i1; i2 < len; i2++) {
|
||||||
uint32_t b = sigs[i2].sign;
|
uint32_t b = sigs[i2].sign;
|
||||||
if (a & b) { continue; }
|
if (a & b) { continue; }
|
||||||
uint32_t ab = a | b;
|
uint32_t ab = a | b;
|
||||||
PRINT2
|
PRINT2
|
||||||
|
|
||||||
for (uint32_t i3 = i2+1; i3 < len; i3++) {
|
for (uint32_t i3 = starts[i2]+i2; i3 < len; i3++) {
|
||||||
uint32_t c = sigs[i3].sign;
|
uint32_t c = sigs[i3].sign;
|
||||||
if (ab & c) { continue; }
|
if (ab & c) { continue; }
|
||||||
uint32_t abc = ab | c;
|
uint32_t abc = ab | c;
|
||||||
PRINT3
|
PRINT3
|
||||||
|
|
||||||
for (uint32_t i4 = i3+1; i4 < len; i4++) {
|
for (uint32_t i4 = starts[i3]+i3; i4 < len; i4++) {
|
||||||
uint32_t d = sigs[i4].sign;
|
uint32_t d = sigs[i4].sign;
|
||||||
if (abc & d) { continue; }
|
if (abc & d) { continue; }
|
||||||
uint32_t abcd = abc | d;
|
uint32_t abcd = abc | d;
|
||||||
PRINT4
|
PRINT4
|
||||||
|
|
||||||
for (uint32_t i5 = i4+1; i5 < len; i5++) {
|
for (uint32_t i5 = starts[i4]+i4; i5 < len; i5++) {
|
||||||
uint32_t e = sigs[i5].sign;
|
uint32_t e = sigs[i5].sign;
|
||||||
if (abcd & e) { continue; }
|
if (abcd & e) { continue; }
|
||||||
printsigs(sigs, 5, i1, i2, i3, i4, i5);
|
#if FANCYPRINT
|
||||||
|
printsigs(sigs, 5, i1, i2, i3, i4, i5);
|
||||||
|
#else
|
||||||
|
printf("%s, %s, %s, %s, %s\n", sigs[i1].word, sigs[i2].word, sigs[i3].word, sigs[i4].word, sigs[i5].word);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if FIND_ONE
|
#if FIND_ONE
|
||||||
goto loopend;
|
goto loopend;
|
||||||
|
@ -107,5 +133,9 @@ void findWords(signature* sigs, uint32_t len) {
|
||||||
#if FIND_ONE
|
#if FIND_ONE
|
||||||
loopend:
|
loopend:
|
||||||
#endif
|
#endif
|
||||||
|
END_TIME
|
||||||
|
#if FREE
|
||||||
|
free(starts);
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
Loading…
Reference in New Issue