Combinations Repost

  • Thread starter Thread starter Joosy
  • Start date Start date
J

Joosy

Rather than reinvent the wheel, can anyone suggest code to create
combinations and permutations based on the number of elements that need to
be combined?

Example

CombIn (1DArray, 2) would output

12
13
21
23
31
32
 
Not too sure I understand the question.

Do you want all combinations of 2-digit integers?
Then count from 0 to 99 and format as 00.

Do you want all combinations of the numbers from 1 to 3?
Then enter 1,2,3 in cells A2, A3, A4 and B1, C1, D1 and
enter in cell B2 the formula =$A2 & B$1 and copy

Like this;
1 2 3
1 =$A2&B$1 =$A2&C$1
2 =$A3&B$1
3

Ed Ferrero
www.edferrero.com
 
And you can have
PermutationsWithReplacement
CombinationsWithoutReplacement
CombinationsWithReplacement
and limited replacement and ..

Option Explicit

Const N = 3, K = 2
Dim BigSet$(N), Flags%(N)

Sub PermutationsWithoutReplacement()
BigSet(1) = "1"
BigSet(2) = "2"
BigSet(3) = "3"
Call PWR(N, K, "", 0) ' n, k, str, level
End Sub

Sub PWR(pN%, pK%, pStr$, pLvl%)
Dim i1%
If pLvl = pK Then
Debug.Print pStr
Exit Sub
End If
For i1 = 1 To N
If Flags(i1) = 0 Then
Flags(i1) = 1
Call PWR(N, K, pStr & BigSet(i1), pLvl + 1)
Flags(i1) = 0
End If
Next i1
End Sub
 
Rather than reinvent the wheel, can anyone suggest code to create
combinations and permutations based on the number of elements
that need to be combined?

Sure, it's easy. But my first question is: why are you interested?
Perhaps the whole purpose is indeed for __you__ to "reinvent the
wheel". Is this a class assignment?
 
Rather than reinvent the wheel, can anyone suggest code to create
combinations and permutations based on the number of elements
that need to be combined?

Sure, it's easy. But my first question is: why are you interested?
Perhaps the whole purpose is indeed for __you__ to "reinvent the
wheel". Is this a class assignment?


You just gave me my first real chuckle of the day and reinforced that you
never know in forums whether you a dealing with a ten year-old whiz kid or a
Nonagenarian.

I'm not quite at the latter yet. This is intended as a parting gesture at
work after thirty-five years. Some will appreciate it. Some will not. Its a
follow up to an Excel (self taught) project completed years ago. Some bright
spark invented some very narrow rules relating to the work processes this
tool helps design. This is intended only as Q&D tool to develop sample sets
that what can be done in a set number of 7-day weeks is finite and that the
constraints are too constrictive. There are only so many combinations that
can be considered.

I haven't been able to focus on Excel or Access for about five years. You
don't know how much VBA develops your thought processes until you suffer
rust and sludge from lack of use. I would once have worked through this as a
self-disciplined learning exercise but, I now have 73 working days remaining
and incredible pressure to pass on a vast array of experience and knowledge
unrelated to programming - before hand over to my replacement who is yet to
arrive can start.

One of life's lessons. You really appreciate how precious time is when you
have a finite amount of time to wrap up all those things you always wanted
to achieve. Could be worse. Might be dying <bg>

Oh! No. It's not a class assignment.
 
Back
Top