Serhat Serhat - 4 months ago 15
Vb.net Question

The Fastest Permutation Code Permutating Numbers in VB NET?

There is a famous and the fastest permutation code without any "function" for VB .Net to permutate numbers just in several rows, that I can't remember unfortunately.

Is there anyone know this code? Or know like this?

Some part of the code is here:

Dim L(4) As Byte
Dim I As Byte
Dim K As Byte
Dim J As Byte
dim RESULTS As String

L = {1, 2, 3, 4, 5}

Do
I = 3
Do While I > 0 And L(I) >= L(I + 1)
I -= 1
Loop
K = L(I) : J = 4
Do While J > 0 And L(J) <= K
J -= 1
Loop
RESULTS = L(0) & "," & L(1) & "," & L(2) & "," & L(3) & "," & L(4)

'
'CODES I CAN'T REMEMBER
'

Loop

Answer

It seems like you're looking for this ...

http://www.cut-the-knot.org/do_you_know/AllPerm.shtml (2. Lexicographic order and finding the next permutation)

... ?

In case you are, the starting values for I and J are incorrect (they should be 4 and 5 instead of 3 and 4 respectively). Also the DO loop is not on the outside.

(I know the example uses swap, but that can be replaced with a single colon-delimited line.)