vb.net - The Fastest Permutation Code Permutating Numbers in VB NET -


there famous , fastest permutation code without "function" vb .net permutate numbers in several rows, can't remember unfortunately.

is there know code? or know this?

some part of code here:

update: found it. working codes here:

dim l(4) byte dim byte dim k byte dim j byte dim results string dim ub, ubm1 integer  l = {1, 2, 3, 4, 5}  ub = l.getupperbound(0) ubm1 = ub - 1      = ubm1     while > 0 , l(i) >= l(i + 1)         -= 1     loop     k = l(i)     j = ub     while j > 0 , l(j) <= k         j -= 1     loop      results = l(0) & "," & l(1) & "," & l(2) & "," & l(3) & "," & l(4)      l(i) = l(j)     l(j) = k     array.reverse(l, + 1, ub - i)  loop while j 

it seems you're looking ...

http://www.cut-the-knot.org/do_you_know/allperm.shtml (2. lexicographic order , finding next permutation)

... ?

in case are, starting values i , j incorrect (they should 4 , 5 instead of 3 , 4 respectively).

(i know example uses swap, can replaced single colon-delimited line.)

dim l(4) byte l = {1, 2, 3, 4, 5}  dim k byte  n integer = 1 120 'no. of permutations: 5!     dim byte = 4, j byte = 5      while l(i - 1) >= l(i)         -= 1        end while     while l(j - 1) <= l(i - 1)         j -= 1     end while      k = l(i - 1) : l(i - 1) = l(j - 1) : l(j - 1) = k     += 1 : j = 5     while < j         k = l(i - 1) : l(i - 1) = l(j - 1) : l(j - 1) = k         += 1 : j -= 1     end while      dim result string = l(0) & "," & l(1) & "," & l(2) & "," & l(3) & "," & l(4)     'export / print result like, e.g. console.writeline or next 

Comments