Compare commits
2 Commits
a200e3a1a2
...
dab6f45128
Author | SHA1 | Date |
---|---|---|
Nicholas Hope | dab6f45128 | |
Nicholas Hope | e8cf287ebe |
19
Makefile
19
Makefile
|
@ -21,16 +21,17 @@ find_one ?= 0
|
||||||
fancy ?= 0
|
fancy ?= 0
|
||||||
free ?= 0
|
free ?= 0
|
||||||
|
|
||||||
# note: setting deleted to 0 doesn't get any extra words,
|
|
||||||
# but does just about triple the execution time.
|
|
||||||
# I do not recommend setting it to false.
|
|
||||||
delete ?= 1
|
|
||||||
|
|
||||||
CC := clang
|
CC := clang
|
||||||
|
|
||||||
MACROS := -DPRINT_INTERMEDIATES=$(printing) -DTIME_SECTIONS=$(timing) -DASSUME_SAFE=$(assume) -DFIND_ONE=$(find_one) -DDELETE=$(delete) -DFANCYPRINT=$(fancy) -DFREE=$(free)
|
ifdef asm
|
||||||
|
override asm = -S
|
||||||
|
else
|
||||||
|
override asm =
|
||||||
|
endif
|
||||||
|
|
||||||
FLAGS := -Ofast -Wall -Werror
|
MACROS := -DPRINT_INTERMEDIATES=$(printing) -DTIME_SECTIONS=$(timing) -DASSUME_SAFE=$(assume) -DFIND_ONE=$(find_one) -DFANCYPRINT=$(fancy) -DFREE=$(free) $(asm)
|
||||||
|
|
||||||
|
FLAGS := -Wall -Werror -Ofast
|
||||||
OUTPUT := -o bw
|
OUTPUT := -o bw
|
||||||
|
|
||||||
bw: solvedle.o boilerplate.o
|
bw: solvedle.o boilerplate.o
|
||||||
|
@ -52,9 +53,9 @@ run: bw wordleWords.txt
|
||||||
|
|
||||||
.PHONY: fast
|
.PHONY: fast
|
||||||
fast: solvedle.c boilerplate.c
|
fast: solvedle.c boilerplate.c
|
||||||
$(CC) $(FLAGS) -DPRINT_INTERMEDIATES=0 -DTIME_SECTIONS=0 -DASSUME_SAFE=1 -DFIND_ONE=1 -DDELETE=1 -DFANCYPRINT=0 -DFREE=0 -c $^
|
$(CC) $(FLAGS) -DPRINT_INTERMEDIATES=0 -DTIME_SECTIONS=0 -DASSUME_SAFE=1 -DFIND_ONE=1 -DFANCYPRINT=0 -DFREE=0 -c $^
|
||||||
make bw
|
make bw
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm *.o bw
|
rm *.o *.s bw
|
|
@ -48,7 +48,7 @@ signature* makeArray(FILE * f, uint32_t* arrlen) {
|
||||||
uint32_t s = getsig(word);
|
uint32_t s = getsig(word);
|
||||||
if (s != 0) {
|
if (s != 0) {
|
||||||
// no duplicate word letters in word
|
// no duplicate word letters in word
|
||||||
sigs[i].word = strndup(word, 5);
|
memcpy(sigs[i].word, word, 5);
|
||||||
sigs[i].sign = s;
|
sigs[i].sign = s;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ uint32_t rawWC = 0;
|
||||||
/* </defines> */
|
/* </defines> */
|
||||||
|
|
||||||
typedef struct signature {
|
typedef struct signature {
|
||||||
char * word;
|
char word[5];
|
||||||
uint32_t sign;
|
uint32_t sign;
|
||||||
} signature;
|
} signature;
|
||||||
|
|
||||||
|
|
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