Function Repository Resource:

NextIntegerComposition

Source Notebook

Get the next composition of an integer in canonical order

Contributed by: Wolfram Staff (original content by Sriram V. Pemmaraju and Steven S. Skiena)

ResourceFunction["NextIntegerComposition"][l]

gives the integer composition that follows l in canonical order.

Examples

Basic Examples (1) 

The composition of an integer following the given one:

In[1]:=
ResourceFunction["NextIntegerComposition"][{1, 2, 3}]
Out[1]=

Properties and Relations (2) 

NextIntegerComposition[l] gives the successor to l in the list returned by the resource function IntegerCompositions:

In[2]:=
ResourceFunction["NextIntegerComposition"][{0, 0, 5}]
Out[2]=
In[3]:=
ResourceFunction["IntegerCompositions"][5, 3]
Out[3]=

You can obtain this list by iteratively computing the next integer up to the length of such compositions, which for the integer n split into k parts is Binomial[n+k-1,n]:

In[4]:=
NestList[ResourceFunction["NextIntegerComposition"], {0, 0, 5}, Binomial[5 + 3 - 1, 5] - 1]
Out[4]=

Version History

  • 1.0.0 – 04 March 2020

Related Resources

License Information