public class IntPartitions
extends java.lang.Object
An integer partition contains all sets of numbers which add up to this value. This class allows to iterate over all unique partitions sequencing from higher to lower numbers.
E.g. for the number 4 this will return the following sequence of indexables of IntPartitions.Part
s:
Result (count*number,...) | Meaning |
---|---|
1*4 | 4 = 4 |
1*3,1*1 | 4 = 3 + 1 |
2*2 | 4 = 2 + 2 |
1*2,2*2 | 4 = 2 + 1 + 1 |
4*1 | 4 = 1 + 1 + 1 + 1 |
Modifier and Type | Class and Description |
---|---|
static class |
IntPartitions.Part
One part of a partition.
|
static class |
IntPartitions.Partition
One partition.
|
Constructor and Description |
---|
IntPartitions() |
Modifier and Type | Method and Description |
---|---|
static void |
main(java.lang.String[] args)
Test partitioning.
|
static java.lang.Iterable<IntPartitions.Partition> |
of(int n)
Get an iterable iterating over the integer partitions of the given number.
|
@NotNull public static java.lang.Iterable<IntPartitions.Partition> of(int n)
n
- a positive numberpublic static void main(@NotNull java.lang.String[] args)
args
- at least one positive number