My program takes static input, and then number crunches for a few hours. I am currently using Macros, but is there a better, more "user friendly" way to do this without losing on performance.
I have written a program in C to generate Seed programs from a Befunge program. It is a very long, brute force calculation. So that it can be heavily optimised, the input variables are hardcoded using Macros. However, I was wondering if there was a better way to do this that would lead to the same or better optimisation.
Here's the Mersenne Twister I used: math.sci.hiroshima-u.ac.jp/~m-mat/...
/*
Copyright wizzwizz4 (c) 2015
*/
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include "mt19937ar.h"
/*Settings*/
#define PROGRAM_STRING "\"ck,@!dlroW ,olleH"
#define PROGRAM_LENGTH 18
#define INITIAL_SEED 0
/*End settings*/
/*Meta settings*/
#define PROGRAM_LENGTH_TYPE char
/*End meta settings*/
unsigned long seed = INITIAL_SEED;
char prog[PROGRAM_LENGTH] = PROGRAM_STRING;
/*Ctrl-C Handlers*/
void ignore(int sig) {
signal(SIGINT, ignore);
}
void panic(int sig) {
printf("Quick! Copy the output. Something's trying to close me!");
signal(SIGINT, ignore);
}
void stopped(int sig) {
printf("We got to %u\nPress any key to quit...", seed);
signal(SIGINT, panic);
getchar();
exit(1);
}
void finished(int sig) {
printf("Copied the output? Great.\nPress any key to quit...");
signal(SIGINT, panic);
getchar();
exit(0);
}
/*End Ctrl-C Handlers*/
int main(void) {
signal(SIGINT, stopped);
PROGRAM_LENGTH_TYPE x; /*The program loop character*/
_Bool y; /*Seed === Program?*/
/*Take 32 from the program characters*/
for (x = 0; x < PROGRAM_LENGTH; x++)
prog[PROGRAM_LENGTH] = prog[PROGRAM_LENGTH] - 32;
/*Do the checking*/
while (1) {
init_genrand(seed);
y = 1;
for (x = 0; x < PROGRAM_LENGTH; x++) {
/*Compares generated character to expected one*/
if (prog[PROGRAM_LENGTH] != (char)(genrand_res53() * 96) ) {
y = 0;
break; /*Break if wrong; no sense in checking the rest!*/
}
}
if (y) break; /*If the for loop didn't break, seed was right!*/
seed++;
}
/*Output, and make sure nobody gets hurt*/
printf("COMPLETE Seed program:\n%u %u\nMake sure you copy this down\nPress ^C to quit...", PROGRAM_LENGTH, seed);
}