Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Permutations

  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    Given a list of n characters, is it possible to create code which will produce for further processing:
    • All permutations taken 2 at a time; then
    • All permutations taken 3 at a time; then
    • All permutations taken 4 at a time; then
    • All permutations taken 5 at a time; etc up to
    • All permutations taken n at a time
    I have been pondering this abstract situation for some time without any breakthrough. Given a fixed value for n I believe it would not present a great challenge to create code specific to the task. My problem is in the development of a concept to handle n being passed as an argument.
    Regards
    Don

  2. #2
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts
    I'm kinda math challenged this morning (and when its' this cold!).
    Can you give me an example of what you are trying to do?
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts
    I echo WebGenii's question and wonder if =FACT() is of use in your quest.
    -John ... I float in liquid gardens
    UTC -7ąDS

  4. #4
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by WebGenii View Post
    Can you give me an example of what you are trying to do?
    Let us assume that the project we are trying to develop is passed the five character collection: A; S; D; F; and G. The project would create and pass as arguments for further processing, the data in columns A of the attached workbook.

    • It would first pass each of the 20 data items in column A individually in no particular order for processing;
    • It would then pass each of the 60 data items in column B individually in no particular order for processing;
    • It would then pass each of the 120 data items in column C individually in no particular order for processing;
    • It would then pass each of the 120 data items in column D individually in no particular order for processing;
    Attached Files Attached Files
    Regards
    Don

  5. #5
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Argh! I'm having no luck downloading your sample file.
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  6. #6
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by WebGenii View Post
    Argh! I'm having no luck downloading your sample file.
    Here's the same file as a text file in csv format.
    Attached Files Attached Files
    Regards
    Don

  7. #7
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi Don

    Here is my starter for 10

    It is not complete but hopefully you can finish the number of loops required and possibly using the Mid function instead of the Left function (off to bed soon)

    Code:
    Dim CurrentRow
    Sub GetString()
    	Dim InString As String
    	Dim NewString As String
    	InString = InputBox("Enter text:")
    	
    	ActiveSheet.Columns(1).Clear
    	CurrentRow = 1
    	If Len(InString) < 1 Then Exit Sub
    	For i = 1 To Len(InString)
    	NewString = Left(InString, i)
    	If Len(InString) >= 8 Then
     	MsgBox "Too many permutations!"
     	Exit Sub
    	Else
     	
     	Call Permute("", NewString)
    	End If
    	Next i
    End Sub
    
    Sub Permute(x As String, y As String)
    	Dim i As Integer, j As Integer
    	j = Len(y)
    	If j < 2 Then
     	Cells(CurrentRow, 1) = x & y
     	CurrentRow = CurrentRow + 1
    	Else
     	For i = 1 To j
     	Call Permute(x + Mid(y, i, 1), _
     	Left(y, i - 1) + Right(y, j - i))
     	Next
    	End If
    End Sub
    Jerry

  8. #8
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts
    There is actually a PERMUT function
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  9. #9
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by WebGenii View Post
    There is actually a PERMUT function
    The PERMUT function returns the number of permutations which can be found in a given collection, taken n items at a time. I am not after the quantity, but the actual permutations (arrangements), themselves.
    Regards
    Don

  10. #10
    5 Star Lounger
    Join Date
    Aug 2001
    Location
    Surrey, United Kingdom
    Posts
    1,001
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Don Wells View Post
    The PERMUT function returns the number of permutations which can be found in a given collection, taken n items at a time. I am not after the quantity, but the actual permutations (arrangements), themselves.
    Hi Don

    This is way, way above my head as you probably already know, in an attempt to repay your previous generous help on the board and I have been doing some Googling and this one seems promising as it mentioned the variable 'n' as you have

    http://www.ehow.com/how_4466533_calc...mutations.html

    Hope that is of some use
    Cheers

    Steve

    Asking the questions everbody wants the answers too but feels too stupid to ask themselves :-)

  11. #11
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Don Wells View Post
    The PERMUT function returns the number of permutations which can be found in a given collection, taken n items at a time. I am not after the quantity, but the actual permutations (arrangements), themselves.
    I understand
    I'm trying to do a non-VBA version, I can see why using VBA might be preferable.
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  12. #12
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    Apologies to all. I misstated the original requirements.

    Where permutations do not allow repetition of a collection item, my requirement does. Examples follow:

    The permutations of A; B; and C taken 2 at a time are: AB; AC; BA; BC; CA; and CB

    My requirement of A; B; and C taken 2 at a time are the permutations plus AA; BB; and CC:
    Regards
    Don

  13. #13
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts
    well that just made things a lot easier!
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  14. #14
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Don Wells View Post
    Apologies to all. I misstated the original requirements.

    Where permutations do not allow repetition of a collection item, my requirement does. Examples follow:

    The permutations of A; B; and C taken 2 at a time are: AB; AC; BA; BC; CA; and CB

    My requirement of A; B; and C taken 2 at a time are the permutations plus AA; BB; and CC:
    I assume my offering of the code is not to your liking?
    Jerry

  15. #15
    Bronze Lounger
    Join Date
    Jan 2001
    Posts
    1,418
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Don,
    I started a post on 11/4/2009 very similar to this. I am sorry, but I don't know how to post it. It is entitled "Combinations".
    Good Luck

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •