Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a list of n words (let's say 26). Now I want to get a list of all possible combinations, but with a maximum of k words per row (let's say 5)

So when my word list is: aaa, bbb, ..., zzz I want to get:

aaa
bbb
...
aaabbb
aaaccc
...
aaabbbcccdddeeefff
aaabbbcccdddeeeggg
...

I want to make it variable, so that it will work with any n or k value. There should be no word be twice and every combinations needs to be taken (even if there are very much).

How could I achieve that?

EDIT:

Thank you for your answers. It is not an assignment. Is is just that I forgot the combinations of my password and I want to be sure that I have all combinations tested. Although I have not 26 password parts, but this made it easier to explain what I want.

If there are other people with the same problem, this link could be helpfull:
Generate word combination array in c#

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
160 views
Welcome To Ask or Share your Answers For Others

1 Answer

i wrote simple a function to do this

        private string allState(int index,string[] inStr)
        {
            string a = inStr[index].ToString();
            int l = index+1;
            int k = l;
            var result = string.Empty;
            var t = inStr.Length;
            int i = index;
            while (i < t)
            {
                string s = a;
                for (int j = l; j < k; j++)
                {
                    s += inStr[j].ToString();
                }
                result += s+",";
                k++;
                i++;
            }

            index++;
            if(index<inStr.Length)
                result += allState(index, inStr);
            return result.TrimEnd(new char[] { ',' });
        }

allState(0, new string[] { "a", "b", "c"})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...