Integer Partition without repetition output Error

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
262
Platform
  1. 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):
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.
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

smozgur

BatCoder
Joined
Feb 28, 2002
Messages
1,352
Closing this thread.

Threads are not being "closed" in the MrExcel Message Board. And the "Mark as solution" feature is only to define the useful answer in a question.

If you have your own solution, then it would be great to let the future readers know about it by posting here.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,560
Messages
5,625,507
Members
416,115
Latest member
Gonzo5711

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top