|
(VB) Sub test_A131408()
Dim n As Long, Result As Long
For n = 1 To 9
Result = A131408(n)
Debug.Print n, Result
Cells(3, 3 + n) = Result
Next n
End Sub
Public Function A131408(n As Long)
Dim imsgbox As Integer
Dim i As Long, j As Long, Summe As Long
If n = 0 Then
A131408 = 0
Exit Function
ElseIf n = 1 Then
A131408 = 1
Exit Function
ElseIf n = 2 Then
A131408 = 2
Exit Function
ElseIf n > 2 And n < 13 Then
'Summe = Bell(n)
Summe = ZahlAllerPartitionen(n)
For j = 2 To n - 1
'Summe = Summe + Stirling2(n, j) * A131408(j)
Summe = Summe + ZahlPartitionen(n, j) * A131408(j)
Next j
Else
imsgbox = MsgBox("Illegal input for argument *** n *** !", vbOKOnly, "A131408")
End
End If
A131408 = Summe
End Function
Public Function ZahlAllerPartitionen(n As Long)
Dim k As Long
ZahlAllerPartitionen = 0
For k = 1 To n
ZahlAllerPartitionen = ZahlAllerPartitionen + ZahlPartitionen(n, k)
Next k
End Function
Sub TestZahlPartitonenInTeile()
Dim n As Long, k As Long, Resultat As Long
n = 8
k = 4
Resultat = ZahlPartitionen(n, k)
Debug.Print "TestZahlPartitonen: n, k, Resultat:", n, k, Resultat
End Sub
Public Function ZahlPartitionen(n As Long, k As Long)
' compute recursively the number of partitions of n into k parts.
Dim imsgbox As Integer
If n > 2147483648# Or k > 2147483648# Then
imsgbox = MsgBox("n and k need to be smaller than 2147483648 !", vbOKOnly, "ZahlPartitionen")
End
End If
If (n < 0 Or k < 0) Then
imsgbox = MsgBox("n and k need to be greater than 0 !", vbOKOnly, "ZahlPartitionen")
End
End If
'If k > n Then
'imsgbox = MsgBox("k needs to be <= n !", vbOKOnly, "ZahlPartitionen")
'End
'End If
If k = 1 Then
ZahlPartitionen = 1
Exit Function
ElseIf k = n Then
ZahlPartitionen = 1
Exit Function
ElseIf k > n Then
ZahlPartitionen = 0
Exit Function
End If
ZahlPartitionen = ZahlPartitionen(n - 1, k - 1) + ZahlPartitionen(n - k, k)
End Function
|