Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <windows.h>
- #include <process.h>
- #include <time.h>
- static const char chars[] = "abcdefghijklmnopqrstuvwxyz";
- static const int list_size = sizeof(chars) - 1;
- FILE *fp;
- void permute(int len)
- {
- time_t start, now;
- char *word;
- int *pos;
- int i,j;
- int done = 0;
- start = time(NULL);
- word = calloc(len+1, 1);
- pos = calloc(sizeof(int) * len, 1);
- while(!done)
- {
- for(i = 0; i < len; i++)
- {
- word[i] = chars[pos[i]];
- }
- fprintf(fp, "%s\n", word);
- for(j = len - 1; j >= 0; j--)
- {
- pos[j]++;
- if(pos[j] < list_size)
- break;
- if(j == 0)
- done = 1;
- pos[j] = 0;
- }
- }
- free(word);
- free(pos);
- now = time(NULL);
- printf("Computed all length %i in %lu seconds\n", len, now - start);
- }
- int min = 1;
- int max = 10;
- unsigned __stdcall ThreadFunc(void *arg)
- {
- int i;
- for(i = min + 1; i <= max; i += 2)
- permute(i);
- return 0;
- }
- int main()
- {
- fp = fopen("list.txt", "wb");
- int i;
- for(i = min; i <= max; i++)
- permute(i);
- fclose(fp);
- return 0;
- }
Add Comment
Please, Sign In to add comment