Juggler_IN
Active Member
- Joined
- Nov 19, 2014
- Messages
- 349
- Office Version
- 2003 or older
- Platform
- Windows
I failed to replicate a subroutine which prints integer partitions (without repetitions) to a sheet FOR "integer compositions" (without repetitions).
Integer compositions without repetitions calculator reference link: IntCwr.
My code for integer partitions (without repetitions):
My function for the COUNT of "integer compositions" (without repetitions) is:
How can the intComposition_WR code be modified to output the intPartition_WR sequences for N = a user input integer. Where count of sequences for N is given by the function intPartition_WR_Count.
Integer compositions without repetitions calculator reference link: IntCwr.
My code for integer partitions (without repetitions):
VBA Code:
Public Sub intComposition_WR( _
ByVal n As Long, _
ByVal k As Long, _
ByVal x As String)
Dim i As Long, j As Long
If n = 0& Then
i = Worksheets("Sheet1").Cells(Worksheets("Sheet1").Rows.count, "A").End(xlUp).Row + 1&
Worksheets("Sheet1").Cells(i, "A") = "'" & x
Else
For j = 1& To VBA.IIf(k < n, k, n)
If VBA.InStr(x & " ", " " & j & " ") = 0 Then intComposition_WR n - j, VBA.IIf(k < n, n - j, k - j), x & " " & j
Next j
End If
End Sub
Sub Test_intComposition_WR()
intComposition_WR 6, 6, ""
End Sub
My function for the COUNT of "integer compositions" (without repetitions) is:
VBA Code:
Function intPartition_WR_Count(n As Long, Optional i As Long = 1) As Long
For i = i To (n - 1) \ 2
intPartition_WR_Count = intPartition_WR_Count + intPartition_WR_Count(n - i, i + 1)
Next i
intPartition_WR_Count = intPartition_WR_Count + 1
End Function
How can the intComposition_WR code be modified to output the intPartition_WR sequences for N = a user input integer. Where count of sequences for N is given by the function intPartition_WR_Count.