LIQUIDAMBAR
Messages postés5Date d'inscriptionjeudi 2 février 2006StatutMembreDernière intervention12 mai 2006
-
5 févr. 2006 à 23:48
LIQUIDAMBAR
Messages postés5Date d'inscriptionjeudi 2 février 2006StatutMembreDernière intervention12 mai 2006
-
9 févr. 2006 à 09:47
J'ai trouvé ce programme dans les codes sources et la procédure combinaisons m'est incompréhensible. Merci pour ton aide,
GDM
Private Sub cmdGO_Click()
Dim Valeur(0 To 2) As Integer
Dim i As Integer
Dim N As Long
Dim Fichsortie As Integer
Fichsortie = 1
Open "c:\m.doc" For Output As #1
For i = 0 To 2
If Not IsNumeric(txtSomme(i).Text) Then Exit Sub
Valeur(i) = CInt(txtSomme(i).Text)
Next
With lstCombinaisons
' .Clear
Combinaisons Valeur(0), Valeur(1), Valeur(2)
N = .ListCount
If N < 0 Then N = 2 ^ 16 + N ' dépassement de capacité
.AddItem CStr(N) & " possibilité(s) :", 0
End With
Print #1,
Print #1, CStr(N) & " séries "
Close #1
End Sub
' -------------------------------------------------------------------
' Nom : Combinaisons
' Desc : Cherche k nombres différents, inférieurs ou égaux à N,
' tels que leur somme soit égale à Somme
' -------------------------------------------------------------------
Private Sub Combinaisons( _
ByVal Somme As Integer, ByVal k As Integer, ByVal N As Integer, _
Optional ByVal strComb As String = "")
Dim Min As Integer, Max As Integer
Dim i As Integer
Min = k * (k + 1) / 2
Max = (N + 1) * k - Min
If Somme < Min Or Somme > Max Then Exit Sub
If k = 1 Then ' fin de la récursivité
If Somme <= N Then ' combinaison trouvée
strComb = strComb & CStr(Somme)
lstCombinaisons.AddItem strComb
End If
Print #1, strComb
Else ' lance la récursivité
Max = Somme - k * (k - 1) / 2
Min = (2 * Somme - Max) / k
If N < Max Then Max = N
For i = Max To Min Step -1
Combinaisons Somme - i, k - 1, i - 1, _
strComb & CStr(i) & "+"
Next
End If