I would like to generate permutations of string words that are inputted from a file. I know the count and was wondering if there is an easy way to do this using an arraylist.
Asked
Active
Viewed 554 times
0
-
You mean, given a string consisting of several words, you want to print all the permutations of words that compose that string? If so, that's an easy and fun recursive (or iterative if you like pain) algorithm. – WhirlWind Apr 10 '10 at 16:33
2 Answers
1
Great article on MSDN Magazine: String Permutations
Combination Generator in Linq (this one has a LINQ based answer)
Using the code provided in the above link:
string str = "leniel";
var permutations = GetPermutations(str);
foreach (string s in permutations)
{
Console.WriteLine(s);
}
Console.WriteLine(permutations.Count()); // 720 permutations
Console.ReadLine();
More links to help:
Listing all permutations of a string/integer
Generating (word) combinations (permutations) out of a string
Is there a .NET library that can do string permutations or string expansion?

Community
- 1
- 1

Leniel Maccaferri
- 100,159
- 46
- 371
- 480
-
Thanks for the help. I just realized I had it wrong and what I need to do is combinations of the strings with the order not changing but selection does. Also it should be n(n-1)/2 results. – vbNewbie Apr 12 '10 at 03:54
0
Since this doesn't have a homework
tag, I'd suggest using a std::vector
of words and std::next_permutation
. (If it had a homework
tag, I'd suggest how to implement something like std::next_permutation
.)

sbi
- 219,715
- 46
- 258
- 445
-
-
Its not homework...I have a bunch of nouns I compiled by using SharpNLP and now wish to produce permutations of length 5 using each noun. I realize its a recursive method required but not sure how to implement it since all searches on this does not produce a clear method. But I will keep checking thanks.. – vbNewbie Apr 10 '10 at 19:06