public class EqualSumCombinations
extends java.lang.Object
implements java.lang.Iterable<int[]>
Example Iteration: (2 0 0) -> (1 1 0) -> (1 0 1) -> (0 2 0) -> (0 1 1) -> (0 0 2)
| Constructor and Description |
|---|
EqualSumCombinations(int sum,
int size)
Create an iterator over all possible vectors with a certain number of entries
that are all nonnegative integers that sum to the same amount.
|
| Modifier and Type | Method and Description |
|---|---|
java.util.List<int[]> |
generateAll()
Generate all possible vectors
|
static void |
incrementCounter(int[] counter,
int sum)
Increment a counter that iterates through all possible vectors.
|
java.util.Iterator<int[]> |
iterator() |
public EqualSumCombinations(int sum,
int size)
sum - Desired sum (must be greater than 0)size - Number of integers (must be greater than 1)public java.util.Iterator<int[]> iterator()
iterator in interface java.lang.Iterable<int[]>public static void incrementCounter(int[] counter,
int sum)
counter - Counter to be incrementedsum - Sum of elements in vectorpublic java.util.List<int[]> generateAll()