• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

Alfabe Permütasyonu

  • Konbuyu başlatan Konbuyu başlatan cabara
  • Başlangıç tarihi Başlangıç tarihi
Katılım
5 Şubat 2017
Mesajlar
1
Excel Vers. ve Dili
2010
Türkçe
Selamlar herkese,

Excel'de makro olarak 29 harfin 3-4-5-6-7 harfli permütasyonunu yapmak istiyorum.

İnternette yaptığım araştırma sonucu bu kodu buldum, fakat (8'li deneme kümesinde işlem yaptığımda, sonuçlarda combinasyonlar çıkıyor, 3lü 4lü 5li .. sonuçların seçilmesi için ne yapabilirim?)

Ne yapmalıyım?

Şimdiden teşekkürler,

Kod:

Dim k As Long, Permutation_Table
Sub Permutation()
Dim Data_Input, Permutation_Output
Dim Output_Row As Long, Last_Column As Long, Array_Row As Long

Rows("2:" & Rows.Count).Clear
Last_Column = Cells(1, Columns.Count).End(xlToLeft).Column
Data_Input = Application.Transpose(Application.Transpose(Range("A1", Cells(1, Last_Column))))

k = InputBox("Input the value of k for P(" _
& UBound(Data_Input) & " , k) where k is an integer between 2 and " _
& UBound(Data_Input) & " inclusive.", "Permutation", 1)

Array_Row = WorksheetFunction.Fact(k) * WorksheetFunction.Combin(UBound(Data_Input), k)

ReDim Permutation_Table(1 To Array_Row, 1 To k)

If k >= 2 And k <= UBound(Data_Input) Then
ReDim Permutation_Output(1 To k)
Call Permutation_Generator(Data_Input, Permutation_Output, Output_Row, 1)
Else
MsgBox "The input [" & k & "] is invalid. The input must be an integer between 2 and " _
& UBound(Data_Input) & " inclusive."
End If
Range("A3").Resize(Array_Row, k) = Permutation_Table 'Use this line if UBound(Data_Input) < 10
End Sub

Function Permutation_Generator(Data_Input As Variant, Permutation_Output As Variant, _
Output_Row As Long, Output_Index As Integer)
Dim i As Long, j As Long, P As Boolean

For i = 1 To UBound(Data_Input)
P = True
For j = 1 To Output_Index - 1
If Permutation_Output(j) = Data_Input(i) Then
P = False
Exit For
End If
Next j
If P Then
Permutation_Output(Output_Index) = Data_Input(i)
If Output_Index = k Then
Output_Row = Output_Row + 1
For n = 1 To k
Permutation_Table(Output_Row, n) = Permutation_Output(n)
Next n
Debug.Print Join(Permutation_Output, ",") 'Optional, use this line as the output if UBound(Data_Input) > 9
Else
Call Permutation_Generator(Data_Input, Permutation_Output, Output_Row, Output_Index + 1)
End If
End If
Next i
End Function
 
Geri
Üst