// gcc -O3 -o mor mor.c #include #include #include #include #include #include #include /* this commented part contains the defining morphisms - do not erase h 01213012 31 01201312 0121301312 g 0102012 0212 0121012 01020121012 eta 010203 2013 0132 0102013203 gamma 012021201210120102 012101202120102 012021201020121 012021201210120212010201210120102 */ struct node { struct node *t[3]; }; typedef struct node node; node *r, *cr, *p; int i, j, s, k, l, x, a_o = 3, a_i = 4, lim = 50000, b, a, mot[100000]; char name[100]; FILE *out; node *new_node(){ p = (node*)malloc(sizeof(node)); for(x = 0; x < a_o; x++) p->t[x] = 0; return p; } int** load(char *name){ FILE *in = fopen("mor.c", "r"); char ch[3000]; int **tmp = (int**)malloc(10*sizeof(int*)); for(fgets(ch, 2000, in); strcmp(name, ch); fgets(ch, 2000, in), ch[strlen(ch)-1] = 0); for(fgets(ch, 2000, in), i = 0; strcmp(ch, "\n"); fgets(ch, 2000, in), i++){ tmp[i] = (int*)malloc((strlen(ch)+1)*sizeof(int)); j = 0; if(*ch != 'e') for(; ch[j]; j++) tmp[i][j] = ch[j]-'0'; tmp[i][j] = -1; } fclose(in); return tmp; }//*/ int* apply(int** mor, int* w, int l){ int *tmp = (int*)malloc(l*sizeof(int)); for(i = k = 0; k < l; i++) for(j = 0; (s = mor[w[i]][j]) >= 0 && k < l; j++) tmp[k++] = s; return tmp; }//*/ int* fp(int** mor, int l){ int *tmp = (int*)malloc(l*sizeof(int)); for(*tmp = i = k = 0; k < l; i++) for(j = 0; (s = mor[tmp[i]][j]) >= 0 && k < l; j++) tmp[k++] = s; return tmp; }//*/ node *get_cr(){ p = r; for(x = 0; x < i; x++) p = p->t[mot[x]]; return p; } void check(int* m, int lim, char* ch){ r = new_node(); for(k = 0; k < lim-5*l; k++) for(i = 0, cr = r; i < l; i++){ if(!cr->t[j = m[k+i]]) cr->t[j] = new_node(); cr = cr->t[j]; } sprintf(name, "mor_%s_%d.txt", ch, l); out = fopen(name, "wt"); for(*mot = i = 0; i >= 0;) if(get_cr()->t[mot[i]]) if(i == l-1){ for(j = 0; j <= i; j++) fprintf(out, "%d", mot[j]); fprintf(out, "\n"); here: while(mot[i] == a_o-1) i--; if(i >= 0) mot[i]++; }else mot[++i] = 0; else goto here; fclose(out); } void usage(){ printf("Usage: ./mor l\n"); exit(0); } int main(int ac, char **av){ if(ac != 2) usage(); l = atoi(av[1]); check(apply(load("g"), fp(load("h"), lim), lim), lim, "g_h"); check(apply(load("gamma"), fp(load("eta"), lim), lim), lim, "gamma_eta"); }