IntegerPartitions
IntegerPartitions[n]
lists the possible ways to partition n
into smaller integers.
IntegerPartitions[n, k]
lists the possible ways to partition n
into smaller integers, using up to k
elements.
Attributes[IntegerPartitions] := {Protected}
Simple examples
Find the partitions of 4:
In[1]:= IntegerPartitions[4] Out[1]= {{4}, {3, 1}, {2, 2}, {2, 1, 1}, {1, 1, 1, 1}}
Find the partitions of 10, using a maximum of k = 2 integers:
In[2]:= IntegerPartitions[10, 2] Out[2]= {{10}, {9, 1}, {8, 2}, {7, 3}, {6, 4}, {5, 5}}
Further examples
The partitions of zero is a nested empty List:
In[1]:= IntegerPartitions[0] Out[1]= {{}}