46 lines
781 B
Plaintext
46 lines
781 B
Plaintext
'Permutations - sb
|
|
n=4
|
|
printem = "True"
|
|
For i = 1 To n
|
|
p[i] = i
|
|
EndFor
|
|
count = 0
|
|
Last = "False"
|
|
While Last = "False"
|
|
If printem Then
|
|
For t = 1 To n
|
|
TextWindow.Write(p[t])
|
|
EndFor
|
|
TextWindow.WriteLine("")
|
|
EndIf
|
|
count = count + 1
|
|
Last = "True"
|
|
i = n - 1
|
|
While i > 0
|
|
If p[i] < p[i + 1] Then
|
|
Last = "False"
|
|
Goto exitwhile
|
|
EndIf
|
|
i = i - 1
|
|
EndWhile
|
|
exitwhile:
|
|
j = i + 1
|
|
k = n
|
|
While j < k
|
|
t = p[j]
|
|
p[j] = p[k]
|
|
p[k] = t
|
|
j = j + 1
|
|
k = k - 1
|
|
EndWhile
|
|
j = n
|
|
While p[j] > p[i]
|
|
j = j - 1
|
|
EndWhile
|
|
j = j + 1
|
|
t = p[i]
|
|
p[i] = p[j]
|
|
p[j] = t
|
|
EndWhile
|
|
TextWindow.WriteLine("Number of permutations: "+count)
|