Moved some boilerplate code to here

master
Nicholas Hope 2022-09-10 14:01:13 -04:00
parent 92fc33bf8b
commit f736b81a44
2 changed files with 87 additions and 0 deletions

19
boilerplate.c Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
#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;
}

68
boilerplate.h Normal file
View File

@ -0,0 +1,68 @@
#include <stdint.h>
#if TIME_SECTIONS
#include <time.h>
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
/* <defines> */
#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
/* </defines> */
typedef struct signature {
char * word;
uint32_t sign;
} signature;
/* <declarations> */
int compare(const void*, const void*);
uint32_t getsig(char*);
void findWords(signature*, uint32_t);
signature* rmdups(signature*);
/* </declarations> */