Solved

Generate Permutation and Combinations of a given string

Posted on 2012-03-16
6
437 Views
Last Modified: 2012-03-26
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.
0
Comment
Question by:Ajay Sharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 250 total points
ID: 37729204
See following example.
I perform it in 2 steps: first create a list of all combinations, and use these to create the permutations
EE.txt
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 37729264
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
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 37729698
Take a look at my answer here:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_27321920.html#a36581969

and change lines 27 thru 30 from:

            for (int i=0; i < input.Length; i++)
            {
                values.Add(input.Substring(i,1));
            }

to:

            values.AddRange(input.Split(" ".ToCharArray()))
0
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
LVL 18

Author Comment

by:Ajay Sharma
ID: 37729900
Thanks a lot Dhaest and Idle_Mind for your quick and valuable inputs.
I will revert after testing your suggested codes.

Thanks
Ajay Sharma
0
 
LVL 18

Author Comment

by:Ajay Sharma
ID: 37764581
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.
0
 
LVL 18

Author Closing Comment

by:Ajay Sharma
ID: 37764586
Thanks
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question