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