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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| Type TCombinaison
Necessaire As Boolean
Tirage(0 To 5) As Byte 'taille de la combinaison
End Type
Function Combinaison(AValeurMax As Integer, ASelection As Integer) As Integer
Dim i As Integer
Dim p As Integer
Dim r As Long
r = 1
p = AValeurMax
For i = 0 To Pred(ASelection)
r = p * r
p = p - 1
Next
p = ASelection
For i = 0 To Pred(ASelection)
r = r \ p
p = p - 1
Next
Result = r
Dim j As Integer, k As Integer, l As Integer
Dim nb_numeros_tires As Integer
Dim nb_numeros_selectionnes As Integer
Dim nb_numeros_objectif As Integer
Dim nb_numeros_max As Integer
Dim combinaisons() As TCombinaison
Dim nb_combinaisons As Integer
Dim nb_numero_communs As Integer
Dim nb_combinaisons_selectionnee As Integer
nb_numeros_tires = 6 ' on part de cette base pour le loto
nb_numeros_max = 49
nb_numeros_objectif = 3
For nb_numeros_selectionnes = nb_numeros_tires To nb_numeros_max
' calcul du nombre de combinaisons possibles
nb_combinaisons = Combinaison(nb_numeros_selectionnes, nb_numeros_tires)
ReDim combinaisons(0 To nb_combinaisons) 'SetLength(combinaisons, nb_combinaisons)
'System.Writeln(Format('Selection : %d '#7' Combinaisons : %d', (nb_numeros_selectionnes, nb_combinaisons)))
' remplissage du tableau faire une variable pour tableau de taille 3 à 10 max
combinaisons(0).Tirage(0) = 1
combinaisons(0).Tirage(1) = 2
combinaisons(0).Tirage(2) = 3
combinaisons(0).Tirage(3) = 4
combinaisons(0).Tirage(4) = 5
combinaisons(0).Tirage(5) = 6
combinaisons(0).Necessaire = True ' Par défaut on garde tout
If High(combinaisons) > 0 Then
For i = 1 To High(combinaisons)
For j = 0 To High(combinaisons(i).Tirage)
combinaisons(i).Tirage(j) = combinaisons(i - 1).Tirage(j)
Next
j = High(combinaisons(i).Tirage)
combinaisons(i).Tirage(j) = combinaisons(i).Tirage(j) + 1
Do While combinaisons(i).Tirage(j) > (nb_numeros_selectionnes + j _
- High(combinaisons(i).Tirage))
combinaisons(i).Tirage(j - 1) = combinaisons(i).Tirage(j - 1) + 1
j = j - 1
Loop
For j = 1 To High(combinaisons(i).Tirage)
If combinaisons(i).Tirage(j) > (nb_numeros_selectionnes + j _
- High(combinaisons(i).Tirage)) Then
combinaisons(i).Tirage(j) = combinaisons(i).Tirage(j - 1) + 1
End If
Next
combinaisons(i).Necessaire = True
Next
End If
' Recherche des combinaisons nécessaires
nb_combinaisons_selectionnee = 0
For i = 0 To Pred(nb_combinaisons)
If combinaisons(i).Necessaire Then
nb_combinaisons_selectionnee = nb_combinaisons_selectionnee + 1
For j = i + 1 To Pred(nb_combinaisons)
nb_numero_communs = 0
For k = 0 To High(combinaisons(i).Tirage)
For l = 0 To High(combinaisons(j).Tirage)
If combinaisons(i).Tirage(k) = combinaisons(j).Tirage(l) Then
nb_numero_communs = nb_numero_communs + 1
If nb_numero_communs = nb_numeros_objectif Then Exit For
End If
Next
If nb_numero_communs = nb_numeros_objectif Then Exit For
Next
If nb_numero_communs = nb_numeros_objectif Then
combinaisons(j).Necessaire = False
End If
Next
End If
Next
' Affichage
'Writeln(Format('%d combinaisons necessaires', (nb_combinaisons_selectionnee)))
For i = 0 To Pred(nb_combinaisons)
If combinaisons(i).Necessaire Then
For j = 0 To High(combinaisons(i).Tirage)
'write(Format('%.2d ', (Combinaisons(i).Tirage(j))))
Next
'writeln('')
End If
Next
Next
End Function |
Partager