• Permutations

    Author
    Topic
    #465449

    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.

    Viewing 9 reply threads
    Author
    Replies
    • #1196116

      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?

      • #1196282

        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:D 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;
    • #1196127

      I echo WebGenii’s question and wonder if =FACT() is of use in your quest.

    • #1196310

      Argh! I’m having no luck downloading your sample file.

      • #1196324

        Argh! I’m having no luck downloading your sample file.

        Here’s the same file as a text file in csv format.

    • #1196363

      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) = 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
      
      
    • #1196366

      There is actually a PERMUT function

      • #1196453

        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.

        • #1196555

          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_calculate-combinations-permutations.html

          Hope that is of some use

        • #1196689

          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.

    • #1196700

      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:

      • #1196746

        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?

        • #1196954

          I assume my offering of the code is not to your liking?

          Hi Jerry

          Thank you for the code offering. Although it introduced me to the concept of a given procedure calling itself (a new revelation for me), I cannot as yet see how to force it to return all results of one-character length; then all results of two-character length etc.

          I am still toying (wrestling), with it.

    • #1196743

      well that just made things a lot easier!

    • #1196803

      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

    • #1196806

      How about this …combinations

    • #1197116

      Thanks for the input folks; It got me thinking in new directions. The solution is attached. Use it ethically.

    Viewing 9 reply threads
    Reply To: Reply #1196743 in Permutations

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel