lrobbo314
Well-known Member
- Joined
- Jul 14, 2008
- Messages
- 3,948
- Office Version
- 365
- Platform
- Windows
I know this has been covered, and believe me, I've looked around, but I haven't found a solution yet.
I am trying to figure out how to write a recursive function that will give every possible combination given a certain group size.
So, if the array is {1,2,3,4,5} and the group size is 3, I will get
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5
And if I bump the group size to 4, I will get
1 2 3 4
1 2 3 5
1 2 4 5
1 3 4 5
2 3 4 5
I've tried to diagram out the sequence of events, as in table below, to try and figure out the code, but I've just been banging my head against the table.
So, if someone could help out and show me how this would work as a recursive VBA solution. Recursion has always made my head hurt.
<caption>
</caption><colgroup><col style="width: 54px"><col width="133"><col width="149"><col width="133"><col width="133"><col width="133"><col width="133"><col width="133"></colgroup><tbody>
</tbody>
I am trying to figure out how to write a recursive function that will give every possible combination given a certain group size.
So, if the array is {1,2,3,4,5} and the group size is 3, I will get
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5
And if I bump the group size to 4, I will get
1 2 3 4
1 2 3 5
1 2 4 5
1 3 4 5
2 3 4 5
I've tried to diagram out the sequence of events, as in table below, to try and figure out the code, but I've just been banging my head against the table.
So, if someone could help out and show me how this would work as a recursive VBA solution. Recursion has always made my head hurt.
C | D | E | F | G | H | I | |
---|---|---|---|---|---|---|---|
1 | 1 | 7 | 16 | 28 | 3 | 19 | Results |
2 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 7 |
3 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 16 |
4 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 28 |
5 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 3 |
6 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 19 |
7 | 1 | 7 | 16 | 28 | 3 | 19 | 7, 16 |
8 | 1 | 7 | 16 | 28 | 3 | 19 | 7, 28 |
9 | 1 | 7 | 16 | 28 | 3 | 19 | 7, 3 |
10 | 1 | 7 | 16 | 28 | 3 | 19 | 7, 19 |
11 | 1 | 7 | 16 | 28 | 3 | 19 | 16, 28 |
12 | 1 | 7 | 16 | 28 | 3 | 19 | 16, 3 |
13 | 1 | 7 | 16 | 28 | 3 | 19 | 16, 19 |
14 | 1 | 7 | 16 | 28 | 3 | 19 | 28, 3 |
15 | 1 | 7 | 16 | 28 | 3 | 19 | 28, 19 |
16 | 1 | 7 | 16 | 28 | 3 | 19 | 3, 19 |
17 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 7, 16 |
18 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 7, 28 |
19 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 7, 3 |
20 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 7, 19 |
21 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 16, 28 |
22 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 16, 3 |
23 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 16, 19 |
24 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 28, 3 |
25 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 28, 19 |
26 | 1 | 7 | 16 | 28 | 3 | 19 | 1, 3, 19 |
<caption>
</caption><colgroup><col style="width: 54px"><col width="133"><col width="149"><col width="133"><col width="133"><col width="133"><col width="133"><col width="133"></colgroup><tbody>
</tbody>