Click or drag to resize

IntegerPartitionGetPartitions Method

Enumerates all partitions of the given integer

Namespace:  Meta.Numerics.Functions
Assembly:  Meta.Numerics (in Meta.Numerics.dll) Version: 4.1.4
public static IEnumerable<IntegerPartition> GetPartitions(
	int n


Type: SystemInt32
The integer to partition, which must be positive.

Return Value

Type: IEnumerableIntegerPartition
An enumeration of all partitions of the given integer.
ArgumentOutOfRangeExceptionn is not positive.

Integer partitions are ways to write an integer as a sum of smaller integers. For example, the integer 4 has 5 partitions: 4, 3 + 1, 2 + 2, 2 + 1 + 1, and 1 + 1 + 1 + 1.

Integer partitions appear in combinatoric problems and solutions to problems that may be mapped into combinatoric problems. For example, the terms which appear in Faà di Bruno's formula correspond to integer partitions.

The number of partitions grows very rapidly with n. Since enumerating through partitions does not require us to count them, no overflows will occur even for large values of n. However, completing the enumeration of such a large number of partitions will take a long time, even though our algorithm produces each partition very quickly. For example, there are about two hundred million partitions of the integer 100.

See Also