27 lines
918 B
Plaintext
27 lines
918 B
Plaintext
Function ConjuntoPotencia(set() As String) As String
|
|
If Ubound(set,1) > 31 Then Print "Set demasiado grande para representarlo como un entero" : Exit Function
|
|
If Ubound(set,1) < 0 Then Print "{}": Exit Function ' Set vacío
|
|
Dim As Integer i, j
|
|
Dim As String s = "{"
|
|
For i = Lbound(set) To (2 Shl Ubound(set,1)) - 1
|
|
s += "{"
|
|
For j = Lbound(set) To Ubound(set,1)
|
|
If i And (1 Shl j) Then s += set(j) + ","
|
|
Next j
|
|
If Right(s,1) = "," Then s = Left(s,Len(s)-1)
|
|
s += "},"
|
|
Next i
|
|
Return Left(s,Len(s)-1) + "}"
|
|
End Function
|
|
|
|
Print "El power set de [1, 2, 3, 4] comprende:"
|
|
Dim As String set(3) = {"1", "2", "3", "4"}
|
|
Print ConjuntoPotencia(set())
|
|
Print !"\nEl power set de [] comprende:"
|
|
Dim As String set0()
|
|
Print ConjuntoPotencia(set0())
|
|
Print "El power set de [[]] comprende:"
|
|
Dim As String set1(0) = {""}
|
|
Print ConjuntoPotencia(set1())
|
|
Sleep
|