COMPLETE permutations from permutations

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
349
Office Version
  1. 2003 or older
Platform
  1. Windows
How can the code for permutations (appended) be modified to output only complete permutations. A complete permutation is a permutation of the order of distinct items in which no item appears in its original place.
VBA Code:
Sub GetTEXT()

    Dim x As String, n As Long

    Application.ScreenUpdating = False

    x = Application.InputBox("Text:", , , , , , , 2)

    If Len(x) < 2 Then Exit Sub
    If Len(x) >= 8 Then
        MsgBox "Too many permutations!"
        Exit Sub
    Else
        ActiveSheet.Columns(1).Clear
        n = 1
        Call GetPERM("", x, n)
    End If

    Application.ScreenUpdating = True

End Sub
Sub GetPERM(ByRef u As String, ByRef v As String, ByRef w As Long)

    Dim i As Integer, n As Integer

    n = Len(v)
    If n < 2 Then
        Range("A" & w) = u & v
        w = w + 1
    Else
        For i = 1 To n
            Call GetPERM(u + Mid(v, i, 1), Left(v, i - 1) + Right(v, n - i), w)
        Next
    End If

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Attaching a reference link Complete Permutations. A derangement is a permutation of the order of distinct items in which no item appears in its original place. For example, the only two derangements of the three items (0, 1, 2) are (1, 2, 0), and (2, 0, 1).
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,650
Messages
6,126,010
Members
449,280
Latest member
Miahr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top