Guest User

Untitled

a guest
Jun 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <windows.h>
  5. #include <process.h>
  6. #include <time.h>
  7.  
  8. static const char chars[] = "abcdefghijklmnopqrstuvwxyz";
  9. static const int list_size = sizeof(chars) - 1;
  10. FILE *fp;
  11.  
  12. void permute(int len)
  13. {
  14. time_t start, now;
  15. char *word;
  16. int *pos;
  17. int i,j;
  18. int done = 0;
  19.  
  20. start = time(NULL);
  21.  
  22. word = calloc(len+1, 1);
  23. pos = calloc(sizeof(int) * len, 1);
  24. while(!done)
  25. {
  26. for(i = 0; i < len; i++)
  27. {
  28. word[i] = chars[pos[i]];
  29. }
  30.  
  31. fprintf(fp, "%s\n", word);
  32.  
  33. for(j = len - 1; j >= 0; j--)
  34. {
  35. pos[j]++;
  36. if(pos[j] < list_size)
  37. break;
  38.  
  39. if(j == 0)
  40. done = 1;
  41.  
  42. pos[j] = 0;
  43. }
  44. }
  45. free(word);
  46. free(pos);
  47.  
  48. now = time(NULL);
  49.  
  50. printf("Computed all length %i in %lu seconds\n", len, now - start);
  51. }
  52.  
  53. int min = 1;
  54. int max = 10;
  55.  
  56. unsigned __stdcall ThreadFunc(void *arg)
  57. {
  58. int i;
  59. for(i = min + 1; i <= max; i += 2)
  60. permute(i);
  61.  
  62. return 0;
  63. }
  64.  
  65. int main()
  66. {
  67. fp = fopen("list.txt", "wb");
  68.  
  69. int i;
  70. for(i = min; i <= max; i++)
  71. permute(i);
  72.  
  73. fclose(fp);
  74.  
  75. return 0;
  76. }
Add Comment
Please, Sign In to add comment