diff --git a/boilerplate.c b/boilerplate.c new file mode 100644 index 0000000..2848a59 --- /dev/null +++ b/boilerplate.c @@ -0,0 +1,19 @@ +#include +#include "boilerplate.h" + +int compare(const void * a, const void * b) { + return ((signature *)a)->sign - ((signature *)b)->sign; +} + +uint32_t getsig(char * word) { + uint32_t result = 0; + for (uint32_t i = 0; i < 5; i++) { + uint32_t bit = 1u << (word[i] & CHARMASK); + if (result & bit) { + // duplicate letters + return 0; + } + result |= bit; + } + return result; +} \ No newline at end of file diff --git a/boilerplate.h b/boilerplate.h new file mode 100644 index 0000000..f50033f --- /dev/null +++ b/boilerplate.h @@ -0,0 +1,68 @@ +#include + +#if TIME_SECTIONS + #include + + clock_t start, end; + double section_time; + char * curr_section; + + #define START_TIME(section_name) do {\ + curr_section = section_name;\ + fprintf(stderr, "BEGIN %s\n", curr_section);\ + start = clock();\ + } while (0); + + #define END_TIME do {\ + end = clock();\ + section_time = ((double) (end - start)) / CLOCKS_PER_SEC;\ + fprintf(stderr, "END %s, %fs\n\n", curr_section, section_time);\ + } while (0); + +#else + // TIME_SECTIONS not specified, define to be nothing + #define START_TIME(section_name) 0; + #define END_TIME 0; + +#endif + +/* */ + #define WORDS 12971 + #define WORDLEN 5 + #define CHARMASK ~0b1100000u + + #define A_BIT 0b10 + #define B_BIT 0b100 + #define C_BIT 0b1000 + #define D_BIT 0b10000 + + + #if PRINT_INTERMEDIATES + #define PRINT2\ + printf("%s, %s\n", sigs[i1].word, sigs[i2].word); + + #define PRINT3\ + printf("%s, %s, %s\n", sigs[i1].word, sigs[i2].word, sigs[i3].word); + + #define PRINT4\ + printf("%s, %s, %s, %s\n", sigs[i1].word, sigs[i2].word, sigs[i3].word, sigs[i4].word); + #else + #define PRINT2 0; + #define PRINT3 0; + #define PRINT4 0; + #endif +/* */ + +typedef struct signature { + char * word; + uint32_t sign; +} signature; + +/* */ + int compare(const void*, const void*); + + uint32_t getsig(char*); + + void findWords(signature*, uint32_t); + signature* rmdups(signature*); +/* */