Find index instead of distance
parent
e8cf287ebe
commit
dab6f45128
43
solvedle.c
43
solvedle.c
|
@ -40,17 +40,12 @@ int main(int argc, char * argv[]) {
|
||||||
fprintf(stderr, "INTERMEDIATE: kept %u words with 5 unique letters\n", i);
|
fprintf(stderr, "INTERMEDIATE: kept %u words with 5 unique letters\n", i);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DELETE
|
START_TIME("sorting")
|
||||||
START_TIME("sorting")
|
qsort(sigs, fiveUniqWC, sizeof(signature), compare);
|
||||||
qsort(sigs, fiveUniqWC, sizeof(signature), compare);
|
END_TIME
|
||||||
END_TIME
|
|
||||||
|
|
||||||
START_TIME("removing duplicates")
|
START_TIME("removing duplicates")
|
||||||
uint32_t cookedWC = rmdups(sigs, fiveUniqWC);
|
uint32_t cookedWC = rmdups(sigs, fiveUniqWC);
|
||||||
END_TIME
|
|
||||||
#else
|
|
||||||
uint32_t cookedWC = fiveUniqWC;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#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);
|
||||||
|
@ -63,9 +58,6 @@ int main(int argc, char * argv[]) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FREE
|
#if FREE
|
||||||
for (uint32_t i = 0; i < fiveUniqWC; i++) {
|
|
||||||
free(sigs[i].word);
|
|
||||||
}
|
|
||||||
free(sigs);
|
free(sigs);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -78,44 +70,43 @@ void findWords(signature* restrict sigs, const uint32_t len) {
|
||||||
// a word that shares no letters with it, and
|
// a word that shares no letters with it, and
|
||||||
// store the distance between the two.
|
// store the distance between the two.
|
||||||
uint32_t endindex = 0;
|
uint32_t endindex = 0;
|
||||||
uint32_t * starts = calloc(len, sizeof(uint32_t));
|
uint32_t* starts = calloc(len, sizeof(uint32_t));
|
||||||
for (uint32_t i = 0; endindex < len && i < len; endindex++) {
|
for (uint32_t i = 0; endindex < len && i < len; endindex++) {
|
||||||
uint32_t sig = sigs[endindex].sign;
|
uint32_t sig = sigs[endindex].sign;
|
||||||
for (i = endindex+1; i < len; i++) {
|
for (i = endindex+1; i < len; i++) {
|
||||||
if ((sig & sigs[i].sign) == 0) {
|
if ((sig & sigs[i].sign) == 0) {
|
||||||
starts[endindex] = i - endindex;
|
starts[endindex] = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
starts[endindex-1] = endindex-1;
|
||||||
END_TIME
|
END_TIME
|
||||||
|
|
||||||
#define START(var) starts[var] + var
|
#define START(var) (starts[var]-1)
|
||||||
START_TIME("finding words")
|
START_TIME("finding words")
|
||||||
// the big loop.
|
// the big loop.
|
||||||
for (uint32_t i1 = 0; i1 < endindex; i1++) {
|
for (uint32_t i1 = 0; i1 < len; i1++) {
|
||||||
const uint32_t a = sigs[i1].sign;
|
uint32_t a = sigs[i1].sign;
|
||||||
|
|
||||||
for (uint32_t i2 = START(i1); i2 < endindex; i2++) {
|
for (uint32_t i2 = START(i1); i2 < endindex; i2++) {
|
||||||
do { i2++; } while (a & sigs[i2].sign);
|
do { i2++; } while (a & sigs[i2].sign);
|
||||||
const uint32_t ab = a | sigs[i2].sign;
|
uint32_t ab = a | sigs[i2].sign;
|
||||||
PRINT2
|
PRINT2
|
||||||
|
|
||||||
for (uint32_t i3 = START(i2); i3 < endindex; i3++) {
|
for (uint32_t i3 = START(i2); i3 < endindex; i3++) {
|
||||||
do { i3++; } while (ab & sigs[i3].sign);
|
do { i3++; } while (ab & sigs[i3].sign);
|
||||||
const uint32_t abc = ab | sigs[i3].sign;
|
uint32_t abc = ab | sigs[i3].sign;
|
||||||
PRINT3
|
PRINT3
|
||||||
|
|
||||||
for (uint32_t i4 = START(i3); i4 < endindex; i4++) {
|
for (uint32_t i4 = START(i3); i4 < endindex; i4++) {
|
||||||
const uint32_t d = sigs[i4].sign;
|
if (abc & sigs[i4].sign) { continue; }
|
||||||
if (abc & d) { continue; }
|
uint32_t abcd = abc | sigs[i4].sign;
|
||||||
const uint32_t abcd = abc | d;
|
|
||||||
PRINT4
|
PRINT4
|
||||||
|
|
||||||
const uint32_t i5start = START(i4);
|
uint32_t i5start = START(i4);
|
||||||
for (uint32_t i5 = MAX(endindex, i5start); i5 < len; i5++) {
|
for (uint32_t i5 = MAX(endindex, i5start); i5 < len; i5++) {
|
||||||
const uint32_t e = sigs[i5].sign;
|
if (abcd & sigs[i5].sign) { continue; }
|
||||||
if (abcd & e) { continue; }
|
|
||||||
#if FANCYPRINT
|
#if FANCYPRINT
|
||||||
printsigs(sigs, 5, i1, i2, i3, i4, i5);
|
printsigs(sigs, 5, i1, i2, i3, i4, i5);
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in New Issue