About
Pricing
Community
Teams
Start Free Trial
Log in
Ajay Sharma
asked on
3/16/2012
Generate Permutation and Combinations of a given string
Hi,
I have a String (e.g. GUIDE ANTIMICROBIAL TARGET) which contains some words ( one or more).
I want to generate all Permutations and Combinations with these words and the output should be like following:
Level1
GUIDE
ANTIMICROBIAL
TARGET
Level2
GUIDE ANTIMICROBIAL
ANTIMICROBIAL GUIDE
GUIDE TARGET
TARGET GUIDE
TARGET ANTIMICROBIAL
ANTIMICROBIAL TARGET
Level3
GUIDE ANTIMICROBIAL TARGET
......... of all 3 words ...........
kindly suggest some code which will generate strings for all levels (1,2,3) and only provide the C# codes.
C#
ASP.NET
.NET Programming
6
2
Last Comment
Ajay Sharma
8/22/2022 - Mon
SOLUTION
Dirk Haest
3/16/2012
THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dirk Haest
3/16/2012
Attached an improved version where you can pass more than 3 words (and it will work).
Also possible to tell which permutation level you want
Testing is included see
private void Form1_Load(object sender, EventArgs e)
{
List<string> combination = CombinateWords(new[] { "bat","cow","dog","mouse" },null);
List<string> permutations = new List<string>();
foreach (string combinatedString in combination)
{
permutations.AddRange(Perm
uteWords(c
ombinatedS
tring));
}
List<string> permutLevel = CombinationPermutation(new
[] {"bat", "cow", "dog", "mouse"}, 2);
}
EE.txt
ASKER CERTIFIED SOLUTION
Mike Tomlinson
3/16/2012
THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ajay Sharma
3/16/2012
ASKER
Thanks a lot Dhaest and Idle_Mind for your quick and valuable inputs.
I will revert after testing your suggested codes.
Thanks
Ajay Sharma
Ajay Sharma
3/26/2012
ASKER
I didn't got time to apply your codes but one of my Google search gave me this famous PermuteUtils link. It worked great for me after modifying a bit.
Thanks all for your time, efforts and help.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Ajay Sharma
3/26/2012
ASKER
Thanks
Also possible to tell which permutation level you want
Testing is included see
private void Form1_Load(object sender, EventArgs e)
{
List<string> combination = CombinateWords(new[] { "bat","cow","dog","mouse" },null);
List<string> permutations = new List<string>();
foreach (string combinatedString in combination)
{
permutations.AddRange(Perm
}
List<string> permutLevel = CombinationPermutation(new
}