Creating combinations where order IS important

fboehlandt

Active Member
Joined
Sep 9, 2008
Messages
334
Hi everyone.
Upfront, apologies for the millionth question regarding permutations / combinations. I'm referring to this thread below about permutations and combinations:

http://www.mrexcel.com/forum/showthread.php?t=510330&highlight=permutation+ABC

I have noted that the suggested VBA code does not make provisions for cases where the order is important and the objective is to create combinations. For example, k = 2 out of n = 5 where the elements are A B C D E would yield:

AB
AC
AD
...
DE

In some instance, however, DE may not equal ED. Consequently, the combinations should end on ED. Does anybody have a suggestion or code snippet doing exactly that?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Is this always going to be 2 out of 5? Or are you going to want this to be any selection from any amount?
 
Upvote 0
I would like to allow for different selections and amounts. That is, within reason: the number of combinations (and permutations in particular) can quickly reach exorbitant sizes. I can probably make the changes myself using the original code. I was just wondering if anybody else has stumbled across this?
Essentially, there are four dimensions when 'drawing balls from and urn':
- order is relevant vs order is irrelevant (permutations vs combinations)
- replacement vs non-replacement
The existing code addresses the first dimension but not the second one (thus, my initial question got it exactly wrong). In the simplest example drawing 2 out of three elements A B C:

Combinations / no replacement:
AB
AC
BC

Permutations / no replacement:
AB
BA
AC
CA
BC
CB

Combinations / replacement:
AA
AB
AC
BB
BC
CC

Permutations / replacement:
AA
AB
AC
BA
BB
BC
CA
CB
CC

I need something that does all that for different selections and different amounts. Any help is greatly appreciated...
 
Upvote 0
p.s. of course it is feasible that k (as the number of elements drawn) is larger than n (the amount drawn from), as long as the balls are being replaced. So combinations like the following would be possible:

AAAA
AAAB
...
CCCC

But this isn't really the case with my specific problem.
 
Upvote 0
Thanks Glenn,
that is a good starting point. The code is a bit messy but I can work from here. Also, it is missing option three aka combinations / replacement. I shall post again once I have the complete code. Thanks again
 
Upvote 0
That was GTO, not me ( thanks GTO ). Am glad that you're getting somewhere with it.
 
Upvote 0
Glad to be of what help I could be :-) I find Tushar's articles very interesting and informative.
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,405
Members
452,911
Latest member
a_barila

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top