56 lines
1.2 KiB
Plaintext
56 lines
1.2 KiB
Plaintext
Function Perm(x() As Integer) As Boolean
|
|
Dim As Integer i, j
|
|
For i = Ubound(x,1)-1 To 0 Step -1
|
|
If x(i) < x(i+1) Then Exit For
|
|
Next i
|
|
If i < 0 Then Return False
|
|
j = Ubound(x,1)
|
|
While x(j) <= x(i)
|
|
j -= 1
|
|
Wend
|
|
Swap x(i), x(j)
|
|
i += 1
|
|
j = Ubound(x,1)
|
|
While i < j
|
|
Swap x(i), x(j)
|
|
i += 1
|
|
j -= 1
|
|
Wend
|
|
Return True
|
|
End Function
|
|
|
|
Function Particiones(list() As Integer) As String
|
|
Dim As Integer i, j, n, p ', x()
|
|
Dim As String oSS = ""
|
|
n = Ubound(list)
|
|
Dim As Integer x(n)
|
|
For i = 0 To n
|
|
If list(i) Then
|
|
For j = 1 To list(i)
|
|
x(p) = i
|
|
p += 1
|
|
Next j
|
|
End If
|
|
Next i
|
|
Do
|
|
For i = 0 To n
|
|
oSS += " ( "
|
|
For j = 0 To Ubound(x,1)
|
|
If x(j) = i Then oSS += Str(j+1) + " "
|
|
Next j
|
|
oSS += ")"
|
|
Next i
|
|
oSS += Chr(13) + Chr(10)
|
|
Loop Until Not Perm(x())
|
|
Return oSS
|
|
End Function
|
|
|
|
Dim list2(2) As Integer = {1, 1, 1}
|
|
Print "Particiones(1, 1, 1):"
|
|
Print Particiones(list2())
|
|
Dim list3(3) As Integer = {1, 2, 0, 1}
|
|
Print !"\nParticiones(1, 2, 0, 1):"
|
|
Print Particiones(list3())
|
|
|
|
Sleep
|