Skip to content

Instantly share code, notes, and snippets.

@mikealexander
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikealexander/9210861 to your computer and use it in GitHub Desktop.
Save mikealexander/9210861 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
char * generatePattern(int size) {
int i;
// allocate enough memory for array of size+1 characters (the extra is for null termination)
char *pattern = malloc((size+1)*sizeof(char));
for(i=0;i<size-1;i++) {
pattern[i] = 'A';
}
pattern[size-1] = 'B';
pattern[size] = '\0'; // null character at the end to terminate the array
return pattern;
}
// does the same thing as above except all A's... should probably reuse code but I'm a c n00b
char * generateText(int size) {
int i;
char *textArray = malloc((size+1)*sizeof(char));
for(i=0;i<size;i++){
textArray[i] = 'A';
}
textArray[size] = '\0';
return textArray;
}
int main(int arc, char *argv[]) {
int i, patternLength, textLength;
for(i=0;i<20;i++) {
switch(i) {
case 0:
patternLength = 10;
textLength = 10;
break;
case 1:
patternLength = 5;
textLength = 20;
break;
case 2:
patternLength = 4;
textLength = 25;
break;
case 3:
patternLength = 2;
textLength = 50;
break;
case 4:
patternLength = 100;
textLength = 100;
break;
case 5:
patternLength = 50;
textLength = 200;
break;
case 6:
patternLength = 40;
textLength = 250;
break;
case 7:
patternLength = 20;
textLength = 500;
break;
case 8:
patternLength = 1000;
textLength = 1000;
break;
case 9:
patternLength = 500;
textLength = 2000;
break;
case 10:
patternLength = 400;
textLength = 2500;
break;
case 11:
patternLength = 200;
textLength = 5000;
break;
case 12:
patternLength = 10000;
textLength = 10000;
break;
case 13:
patternLength = 5000;
textLength = 20000;
break;
case 14:
patternLength = 4000;
textLength = 25000;
break;
case 15:
patternLength = 2000;
textLength = 50000;
break;
case 16:
patternLength = 100000;
textLength = 100000;
break;
case 17:
patternLength = 50000;
textLength = 200000;
break;
case 18:
patternLength = 40000;
textLength = 250000;
break;
case 19:
patternLength = 20000;
textLength = 500000;
break;
}
// set up array for the directory name
char directory [15];
// format the directory name string
sprintf(directory, "inputs/test%d/", i);
// make the directory if it doesn't exist (CHMOD to 0700 so we can access it)
if (0 != access(directory, F_OK)) {
mkdir(directory, 0700);
}
// setup the pattern filename
char patternfilename [25];
//format the pattern filename string
sprintf(patternfilename, "%spattern.txt", directory);
// open the pattern file (make it if it doesn't exist)
FILE *patternFile = fopen(patternfilename, "wb");
//write the pattern to it
fprintf(patternFile, "%s", generatePattern(patternLength));
fclose(patternFile);
// setup the text filename
char textfilename [25];
// format the text filename string
sprintf(textfilename, "%stext.txt", directory);
// open the text file
FILE *textFile = fopen(textfilename, "wb");
// write to it
fprintf(textFile, "%s", generateText(textLength));
fclose(textFile);
}
}
@mikealexander
Copy link
Author

We probably want to use more imaginative combinations of pattern length and text length... for example for 10^2 perhaps: 10_10, 5_20, 4_25, 2_50...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment