Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permutations of N elements 1

Status
Not open for further replies.

Oughter

Technical User
Oct 23, 2001
2
US
Hey all! I am new to tek-tips, but this is pretty imperative that I know how to do this. I am working on a research project which requires me to

1. List ALL permutations of N elements in which the user inputs.
2. Take those permutations make text boxes labeled by these permutations.

The motivation behind this is as follows. The number that the user inputs determines the number of "points" in n-space. Each point must be assigned a distinct probability, so step 2 is necessary. But as everyone says, BABY STEPS, so 1. is important now. If anyone can give me help on one or the other it would be more than appreciated!

Thanks.
 
Hi,

I posted this code a while ago. The code works fine, but somebody (Strongm?) posted a slightly more elegant version and had some good comments on the exponential amount of results when N increaeses. I can't find the thread (the title was something like 'list all unique combinations..' and definietly included the word 'permutations', is it possible that some threads have been deleted?).

Anyway here's the code:
------------------------------------------------------------
'place a listbox and a button on a form
Const M = 3, N = 3
Dim Item(M) As Integer, Flag(M) As Integer, Queue(M) As Integer, Total As Long
Dim I As Integer

Sub Perm(M As Integer, N As Integer, Level As Integer)
Dim I As Integer, J As Integer, tmp As String

For I = 1 To M
If (Flag(I) = 0) Then
Flag(I) = 1
Queue(Level) = I
If (Level < N) Then
Call Perm(M, N, Level + 1)
Else
Total = Total + 1
tmp = &quot;&quot;
For J = 1 To Level
tmp = tmp & CStr(Item(Queue(J)))
Next
List1.AddItem tmp
Print
End If
Flag(I) = 0
End If
Next
End Sub
Private Sub Command1_Click()
For I = 1 To M
Item(I) = I
Next
Call Perm(M, N, 1)
End Sub
-----------------------------------------------------------

Sunaj
 
I, also, could not find Sunaj's thread, but I did run across another which may be of some help.

thread222-36824

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top