Results 1 to 7 of 7

Thread: [2005] Get all possible combinations of a word letters

  1. #1

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    [2005] Get all possible combinations of a word letters

    Hi!!!

    I have a List with letters with a max length of 10. Lets say for example I have the letters "D","A","D","O". How can I get all the possible combinations that these letters can form like:
    DADO
    DAOD
    DODA
    DOAD
    DDAO
    DDOA
    ADDO
    ADOD
    AODD
    ODDA
    ODAD
    OADD

    In this case i would get 4!/2! combinations because there are two "D". So to have this DADO and switch the "D" i get the same that why I divide it by 2!.
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Get all possible combinations of a word letters

    Take a look a this thread in the code bank
    http://www.vbforums.com/showthread.php?t=432293

  3. #3

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: [2005] Get all possible combinations of a word letters

    not that see what he says:
    Also, I want to mention that the list objects that will be passed to the method should have unique objects in order to get unique lists of objects. For example if we have a set {A,A,B,C} then the method will return:
    and in my example i gave the letters DADO two D.
    I want like this

    Well but maybe I can find the solution from there.
    Last edited by Lasering; Nov 22nd, 2007 at 09:08 AM.
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2005] Get all possible combinations of a word letters

    You do realize that with 10 possible combinations you can end up with an astronomically big set, right? I've always wondered what the purpose was when people wanted to get all combinations of something like this. What are you going to do with it?
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: [2005] Get all possible combinations of a word letters

    Well. I'm at 12 grade and on Math class. I think my teacher is doing something wrong (well she's not that good teacher, she gets wrong a lot). So I tried to explain to her why. But still she says she right, and probably she is. But I want to be sure. So I want to add to a list box all the values of the combinations. And then delete the ones that dont fit the exercise.
    The exercise is like this: How many combinations can you form with the word "INFINITO", so that the letters IN stay always together. In other words you have to have always either IN or NI in the string.
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  6. #6
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: [2005] Get all possible combinations of a word letters

    This is more math than anything. Simple combinations. You have 8 letters, and they can be in any order, such that an I and an N always appear next to each other. So you have 8 possible letters that can go in the first spot. If that letter is an I or an N, you know the next letter has to be the opposite. With two of each, you know that there are only two letters that can fit that criteria. The rest is just a simple factorial. 8*2*6*5*4*3*2*1. If that makes any sense.

  7. #7
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: [2005] Get all possible combinations of a word letters

    Actually, I think you might better understand the question when it is approached like this:

    Since the letters I and N always have to stay together, let us consider them as one letter, and disregard the fact that there are 3 I's and 2 N's for the moment.

    So with our 6 letters, and our 1 lassoed pair, we have a total of 7! possible combinations.

    Now, what about the fact that there are 3 I's? All this means is that there are 3 possible ways of forming 'IN' with reference to the letter I, so now our total goes up to 7! * 3

    How about the 2 N's? Again, this means that there are 2 possible ways of forming 'IN' with reference to the letter N, so now our total goes up to 7! * 3 * 2

    Finally, since 'IN' can also be written as 'NI', we have to double our existing total to account for each possible time that 'IN' could have been 'NI'. This brings our final total to 7! * 3 * 2 * 2 = 60,480.

    Whenever you are dealing with problems like this, with more than one of the same letter that has to be considered, it sometimes helps to substitute different symbols in their place to help you get started. Then when you have a basic result, factor them back in. So essentially what we did was find the total possible permutations of the combination 'N' and 'I', and then bring that into our larger permutation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width