Page 1 of 1

Code question - Creating table of combinations

PostPosted: Wed Nov 09, 2011 12:22 pm
by Memorex
I'm working on something and I can't quite figure it out. Hoping someone here can provide an answer. Mathematics goes with Melodic Rock, right?

So I have 9 groups of value. Let's say there are two values (A & B) in each group. I need to create a table of all the possible combinations.

I do not want to use both A and B from any of the groups in the same combination and I must have at least one value from each group. Example:

Group 1 a & b
Group 2 a & b
Group 3 a & b
etc...

The first group would be [a a a a a a a a a]. The second group might be [a b a a a a a a a].

Obviously I'd like to put this into some kind of loop. For the table, I can write each letter on a separate row, as long as I have some other value in a column that identifies all nine rows as a combination.

Hope that made sense. Thanks in advance if you know how to help.

Re: Code question - Creating table of combinations

PostPosted: Wed Nov 09, 2011 12:26 pm
by S2M
Memorex wrote:I'm working on something and I can't quite figure it out. Hoping someone here can provide an answer. Mathematics goes with Melodic Rock, right?

So I have 9 groups of value. Let's say there are two values (A & B) in each group. I need to create a table of all the possible combinations.

I do not want to use both A and B from any of the groups in the same combination and I must have at least one value from each group. Example:

Group 1 a & b
Group 2 a & b
Group 3 a & b
etc...

The first group would be [a a a a a a a a a]. The second group might be [a b a a a a a a a].

Obviously I'd like to put this into some kind of loop. For the table, I can write each letter on a separate row, as long as I have some other value in a column that identifies all nine rows as a combination.

Hope that made sense. Thanks in advance if you know how to help.


Would a Punnett Square help?

Image

PostPosted: Wed Nov 09, 2011 12:32 pm
by Memorex
Would that only get me all the possible combinations of 2 numbers, including 2 from the same group. Not sure how this works. But in my case, each combination must have nine values, one item from each group (a or b).

PostPosted: Wed Nov 09, 2011 12:38 pm
by S2M
Memorex wrote:Would that only get me all the possible combinations of 2 numbers, including 2 from the same group. Not sure how this works. But in my case, each combination must have nine values, one item from each group (a or b).



Yes...put the first group vertical(like the blue string in my photo)...then put the 2nd group horizontal(like the pink group in the photo).

Then fill in the blank squares with the combinations....

PostPosted: Wed Nov 09, 2011 1:05 pm
by Memorex
I'm sorry - feel like a dunce here - I'm not sure which two groups you mean.

PostPosted: Wed Nov 09, 2011 1:15 pm
by S2M
Memorex wrote:I'm sorry - feel like a dunce here - I'm not sure which two groups you mean.


From your first post:

The first group would be [a a a a a a a a a]. The second group might be [a b a a a a a a a].