# Algorithm for all possible combinations?

• December 2nd, 2012, 08:08 AM
affebaffe
Algorithm for all possible combinations?
Hi i'm doing a simple translation program built from a a glossary and some statistic from a corpus.
Now i have realized that to get my program to work i need a algorithm that can get all the possible combinations from a N*M array.

EX:
[1(A1,A2,A3,......,An),2(B1,B2,B3,......,Bn),3(C1,C 2,C3,......,Cn),........N(N1,N2,N3,......,Nn)]

I haven't been able to solve this and would really need some help.
• December 2nd, 2012, 10:23 AM
Norm
Re: Algorithm for all possible combinations?
With a N*M array are there N*M different elements and (N*M)! different combinations?
• December 2nd, 2012, 10:53 AM
affebaffe
Re: Algorithm for all possible combinations?
Sry if i wasn't clear enough. The first array have a unknown amount of arrays in it and everyone of those arrays have an unknown amount of string in them.
• December 2nd, 2012, 11:09 AM
Norm
Re: Algorithm for all possible combinations?
I don't know how to solve the problem then if all the values are unknown.
All arrays in java are defined with a fixed size. They need not be full, but some how you can determine how many elements they contain.
• December 2nd, 2012, 11:22 AM
affebaffe
Re: Algorithm for all possible combinations?
I think i explained badly again i need the algorithm to work for any amount of values but i will know how many there are for every iteration. For an example
if i need to translate how are you then every word have a couple of different translations that i get from a glossary so the array will be [(all translations of how),(all translation of are),(all translation of you)] .
• December 2nd, 2012, 12:00 PM
Norm
Re: Algorithm for all possible combinations?
Don't see where the talk of combinations comes from. Here is an example of what I thought combinations could be: Given the letters: A,B,C you would get: ABC, ACB, BAC, BCA, CAB, CBA

Can you give a simple concrete example of what you are looking for?
• December 2nd, 2012, 12:33 PM
affebaffe
Re: Algorithm for all possible combinations?
ok with just two words the sentence in swedish "jag är" translates correctly in english to "I am" but if you look it up in a glossery every word will have more then one translation so "jag" can be translated to "I" and "ego" and "är" can be translated to "am", "are" and "is" so the array will look like this:
[("i","ego"),("am","are","is")]
the possible combinations are:
I am
I are
I is
ego am
ego are
ego is

Then the program will use some statistic to compare the different sentences and hopefully it will get the right one most of the time.

In this case the word did't have that many translation and it was a short sentence but the problem is of course that this can vary alot.

I hope the example is enough and i really appreciate that you are trying to help me.
• December 2nd, 2012, 12:45 PM
Norm
Re: Algorithm for all possible combinations?
Looks like a recursive method could do that. Pass it the array of arrays and have it extract one from each sub array and build the output string.
• December 3rd, 2012, 04:51 AM
affebaffe
Re: Algorithm for all possible combinations?
thx it worked perfectly!!!