Comment optimisez mon code ? Systeme de combinaison
Bonjour, voila le code que j'utilise
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
Public Function Komb1(ByVal tableau, ByVal Prefixe As String, ByVal min As Integer, ByVal max As Integer, ByVal n As Integer) As String
Dim i As Integer
Dim Resultat As String
For i = min To max - n + 1
If Prefixe = "-1" Then
Resultat = tableau(i)
Else
Resultat = Prefixe & "*" & tableau(i)
End If
If n > 1 Then
Komb1 tableau, Resultat, i + 1, max, n - 1
Else
If total1 = vbNullString Then
total1 = Resultat
Else
total1 = total1 & "+" & Resultat
End If
End If
Next
Komb1 = total1
End Function |
Rezultat=>
Combinaison de 2 element sur 5 (2/5) -> 10 combinaison possible
A*B+A*C+A*D+A*E+A*F+B*C+B*D+B*E+B*F+C*D+C*E+C*F+D*E+D*F+E*F
Mon probleme c'est que quand je dois calculer de grande combinaison (4/13) ->715 combinaisons possible, le temps de calcul est trop eleve, tout ce qui est superieur a 5s est trop eleve pour moi
Qu'elle est la meilleure maniere de faire ? Puis-je optimiser mon code,stocker dans un tableau, ou dans un fichier ?
Merci