Avatar of Ajay Sharma
Ajay Sharma
Flag for India asked on

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

Avatar of undefined
Last Comment
Ajay Sharma

8/22/2022 - Mon
SOLUTION
Dirk Haest

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

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(PermuteWords(combinatedString));

            }

            List<string> permutLevel = CombinationPermutation(new[] {"bat", "cow", "dog", "mouse"}, 2);
        }
EE.txt
ASKER CERTIFIED SOLUTION
Mike Tomlinson

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

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

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

ASKER
Thanks