PC Review


Reply
Thread Tools Rate Thread

Combinations Repost

 
 
Joosy
Guest
Posts: n/a
 
      6th Feb 2008
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

--
Stevie

"Build a man a fire and he will be warm for one night. Set a man on fire,
and he will be warm for the rest of his life." ~ Sun-Tzu on Fire


 
Reply With Quote
 
 
 
 
Ed Ferrero
Guest
Posts: n/a
 
      6th Feb 2008
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
 
Reply With Quote
 
Dave D-C
Guest
Posts: n/a
 
      6th Feb 2008
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

"Joosy" <Spam@free> wrote:
>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

 
Reply With Quote
 
joeu2004
Guest
Posts: n/a
 
      6th Feb 2008
On Feb 6, 1:49*am, "Joosy" <Spam@free> wrote:
> 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?

 
Reply With Quote
 
Joosy
Guest
Posts: n/a
 
      7th Feb 2008

"joeu2004" <(E-Mail Removed)> wrote in message
news:8a21035e-0552-4128-8a59-(E-Mail Removed)...
On Feb 6, 1:49 am, "Joosy" <Spam@free> wrote:
> 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.

--
Stevie

"Build a man a fire and he will be warm for one night. Set a man on fire,
and he will be warm for the rest of his life." ~ Sun-Tzu on Fire





 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combinations Mattxcore77 Microsoft Excel Programming 1 4th Feb 2009 01:23 AM
All Possible Combinations jhachtel Microsoft Excel Programming 3 6th Aug 2008 03:35 PM
Possible Combinations =?Utf-8?B?UGxlYXNlIEhFTFAhISE=?= Microsoft Excel Misc 1 6th Jan 2006 03:58 PM
All possible combinations Rakesh Microsoft Excel Misc 2 17th Mar 2004 10:20 PM
Combinations GTS Microsoft Excel Misc 1 25th Nov 2003 07:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:22 PM.