fb:porticula NoPaste
Rekursives Kombinieren dreier Zahlen
Uploader: | Sebastian |
Datum/Zeit: | 03.10.2008 13:40:33 |
'Beispiel für rekursives Kombinieren dreier Zahlen
'03.10.2008 - Getestet mit FreeBASIC 0.20.0
DECLARE SUB Kombinier (ByVal t As Integer, ByVal S As String)
DECLARE FUNCTION Spalten (ByVal Zahl As Integer) As String
CONST n = 3
DIM SHARED Werte(0 TO 2) AS INTEGER = {-1, 0, 1}
DIM SHARED KombiCount AS INTEGER = 0
IF n < 1 THEN
Print "Fehler: n wurde zu klein gewaehlt."
Sleep: End
End If
PRINT "Kombinationen:"
PRINT "---"
Kombinier 1,""
PRINT "---"
PRINT "Es gab " & KombiCount & " Kombinationen."
SLEEP: END
SUB Kombinier (ByVal t As Integer, ByVal S As String)
Dim i As Integer, Neu As String
For i = LBound(Werte) to UBound(Werte)
Neu = S
If Neu <> "" Then
Neu += " , "
ELSE
Neu = "{"
END IF
Neu &= Spalten(Werte(i))
IF t = n THEN
PRINT Neu; "}"
KombiCount += 1
ELSE
Kombinier t+1, Neu
END IF
Next i
END SUB
FUNCTION Spalten (ByVal Zahl As Integer) As String
DIM R AS STRING
R = LTRIM(STR(Zahl))
DO
IF LEN(R) < 2 THEN
R = " "+R
ELSE
EXIT DO
END IF
LOOP
RETURN R
END FUNCTION