Every permutation of the alphabet up to 29 characters?

后端 未结 13 1311
攒了一身酷
攒了一身酷 2021-02-11 01:23

I\'m attempting to write a program that will generate a text file with every possible permutation of the alphabet from one character up to twenty-nine characters. I\'ve chosen 2

13条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-11 02:11

    The word "permutation" usually means that each letter appears exactly once, so it would be impossible to generate any permutation with more than 26 letters. Anyway, since the number of generated strings is too big, you can use random strings instead (the following is C code):

    char s[30];
    int p;
    for (;;) // repeat forever: you cannot use a realistic iteration limit anyway
    {
        for (p = 0; p < 29; ++p)
            s[p] = 'a' + rand() % 26;
        s[29] = '\0';
        puts(s);
    }
    

提交回复
热议问题