Dim chosenNumbers(5) As Integer
chosenNumbers(1) = 1
chosenNumbers(2) = 2
chosenNumbers(3) = 3
chosenNumbers(4) = 4
chosenNumbers(5) = 5
Dim numSequences As Integer = 200
Dim sequenceLength As Integer = 5
Dim minMatches As Integer = 4
Dim reducedNumSequences As Integer = 10
Dim sequences(numSequences, sequenceLength) As Integer
For i As Integer = 1 To numSequences
For j As Integer = 1 To sequenceLength
sequences(i, j) = CInt(Math.Floor((10 - 1 + 1) * Rnd())) + 1
Next j
Next i
Dim hasMatch As Boolean = False
For i As Integer = 1 To numSequences
Dim matchCount As Integer = 0
For j As Integer = 1 To sequenceLength
For k As Integer = 1 To 5
If sequences(i, j) = chosenNumbers(k) Then
matchCount += 1
End If
Next k
Next j
If matchCount >= minMatches Then
hasMatch = True
End If
Next i
If Not hasMatch Then
ReDim Preserve sequences(numSequences + 1, sequenceLength)
For i As Integer = 1 To minMatches
sequences(numSequences + 1, i) = chosenNumbers(i)
Next i
For i As Integer = minMatches + 1 To sequenceLength
sequences(numSequences + 1, i) = CInt(Math.Floor(((10 - minMatches) - (minMatches + 1) + 1) * Rnd())) + (minMatches + 1)
Next i
End If
Dim reducedSequences(reducedNumSequences, sequenceLength) As Integer
For i As Integer = 1 To reducedNumSequences
Dim sequenceIndex As Integer = CInt(Math.Floor(((numSequences + IIf(hasMatch, 0, 1)) - 1 + 1) * Rnd())) + 1
For j As Integer = 1 To sequenceLength
reducedSequences(i, j) = sequences(sequenceIndex, j)
Next j
Next i
For i As Integer = 1 To reducedNumSequences
For j As Integer = 1 To sequenceLength
Console.Write(reducedSequences(i, j))
Next j
Console.WriteLine()
Next i
Math.Floor() arrondit le résultat précédent à la valeur inférieure (ressemble à la commande Round en PB)
CInt() convertit le résultat précédent en un entier (équivaut à int en PB)
Pour le reste ce sont des tableaux et des boucles.
Regarde Dim et ReDim dans la doc, les boucles
; Par défaut les variables sont des integer
Procedure IIf(hasMatch, V, F)
If hasMatch
ProcedureReturn V
Else
ProcedureReturn F
EndIf
EndProcedure
Dim chosenNumbers(5)
chosenNumbers(1) = 1
chosenNumbers(2) = 2
chosenNumbers(3) = 3
chosenNumbers(4) = 4
chosenNumbers(5) = 5
numSequences = 200
sequenceLength = 5
minMatches = 4
reducedNumSequences = 10
; CInt arrondit (arrondi du banquier) à l’entier le plus proche au lieu de tronquer la partie fractionnelle des nombres
Dim sequences( sequenceLength,numSequences)
For i = 1 To numSequences
For j = 1 To sequenceLength
rd.f=Random(1000000,0)/1000000
While rd=1.0
rd=Random(1000000,0)/1000000
Wend
sequences(j, i) = Round((Round((10 - 1 + 1) * Rd,#PB_Round_Down)),#PB_Round_Nearest) + 1
Next j
Next i
hasMatch.b = #False
For i = 1 To numSequences
matchCount = 0
For j = 1 To sequenceLength
For k = 1 To 5
If sequences(j, i) = chosenNumbers(k)
matchCount + 1
EndIf
Next k
Next j
If matchCount >= minMatches
hasMatch = True
EndIf
Next i
If Not hasMatch
ReDim sequences(sequenceLength,numSequences + 1)
For i = 1 To minMatches
sequences( i,numSequences + 1) = chosenNumbers(i)
Next i
For i = minMatches + 1 To sequenceLength
rd.f=Random(1000000,0)/1000000
While rd=1.0
rd=Random(1000000,0)/1000000
Wend
sequences(i,numSequences + 1) = Round(Round(((10 - minMatches) - (minMatches + 1) + 1) * Rd,#PB_Round_Down),#PB_Round_Nearest) + (minMatches + 1)
Next i
EndIf
Dim reducedSequences(reducedNumSequences, sequenceLength)
For i = 1 To reducedNumSequences
rd.f=Random(1000000,0)/1000000
While rd=1.0
rd=Random(1000000,0)/1000000
Wend
sequenceIndex = Round(Round(((numSequences + IIf(hasMatch, 0, 1)) - 1 + 1) * Rd,#PB_Round_Down),#PB_Round_Nearest) + 1
For j = 1 To sequenceLength
reducedSequences(i, j) = sequences(j,sequenceIndex)
Next j
Next i
OpenConsole()
For i = 1 To reducedNumSequences
For j = 1 To sequenceLength
Print(Str(reducedSequences(i, j)))
Next j
PrintN("")
Next i
R$ = Input()
jeftaxi a écrit : ven. 14/avr./2023 19:58
Bonjour à tous et merci de m'accepter sur le forum.
J'ai un programme que je n'arrive pas à transformer complètement en PureBasic. Alors si quelqu'un parmi vous peut m'aider, milles merci.
voici le programme :
Demande a shadow. Il a fait un exceeeelent convertisseur VB to PB
Oui mais seul problème, mon convertisseur de code VB vers PB ne fonctionne que pour du code pour générer une fenêtre et ces gadget, pas pour du code VB a proprement parlé !
Merci sinon.