Created
April 12, 2011 19:11
-
-
Save jah2488/916175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dim CurrentRow | |
Sub GetString() | |
Dim InString As String | |
InString = InputBox("Enter text to permute:") | |
If Len(InString) < 2 Then Exit Sub | |
If Len(InString) >= 8 Then | |
MsgBox "Too many permutations!" | |
Exit Sub | |
Else | |
ActiveSheet.Columns(1).Clear | |
CurrentRow = 1 | |
Call GetPermutation("", InString) | |
End If | |
End Sub | |
Sub GetPermutation(x As String, y As String) | |
' The source of this algorithm is unknown | |
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 GetPermutation(x + Mid(y, i, 1), _ | |
Left(y, i - 1) + Right(y, j - i)) | |
Next | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment