public class Combinatorics extends Object
| Modifier and Type | Method and Description |
|---|---|
static List<Integer> |
indexCombinations(double x,
int size,
int elements)
Deprecated.
|
static <T> List<T> |
listCombination(double combination,
int size,
List<T> elementList) |
static <T> List<T> |
multiListCombination(List<FieldRule<T>> rules,
double combinationNumber) |
static double |
nCr(int n,
int r)
Calculates the Binomial Coefficient
|
static BigInteger |
nCrBigInt(int n,
int r)
Calculates the Binomial Coefficient
|
static double |
NNKK(int N,
int n,
int K,
int k)
Calculates the combinations for the hypergeometric probability distribution, that is, it does not divide by
N nCr n. |
static int[] |
specificCombination(int elements,
int size,
BigInteger combinationNumber)
You have x elements and want to pick a specific combination them which will contain y elements.
|
static int[] |
specificCombination(int elements,
int size,
double combination)
You have x elements and want to pick a specific combination them which will contain y elements.
|
public static double NNKK(int N,
int n,
int K,
int k)
N nCr n.
Example: There are 6 fields, 3 of them contains a mine. You have the possibility to take 2 of these at once.
NNKK(6, 3, 2, 0) will return the number of combinations where 0 of the 2 you are taking contains a mine.
N - All elementsn - All elements containing what we are looking forK - How many elements are we looking ink - How many elements we are looking in that contains what we are looking fork interesting elements in K areas when there are n interesting elements in N areas.public static <T> List<T> listCombination(double combination, int size, List<T> elementList)
public static <T> List<T> multiListCombination(List<FieldRule<T>> rules, double combinationNumber)
@Deprecated public static List<Integer> indexCombinations(double x, int size, int elements)
public static double nCr(int n,
int r)
n - number of elements you haver - number of elements you want to pickn elements and want r of thempublic static BigInteger nCrBigInt(int n, int r)
n - number of elements you haver - number of elements you want to pickn elements and want r of thempublic static int[] specificCombination(int elements,
int size,
BigInteger combinationNumber)
For example, you have 5 elements and want 3 of them. There are 10 combinations for this. The exact combinations can be ordered as:
012, 013, 014, 023, 024, 034, 123, 124, 134, 234. Combination number 4 is then 023,
so specificCombination(5, 3, BigInteger.valueOf(4)) will return the array { 0, 2, 3 }
elements - number of elements you havesize - number of elements you want to pickcombinationNumber - the combination number you want to pick. 1 <= combinationNumber <= nCr(elements, size)0 <= value < elementsIllegalArgumentException - if combinationNumber is out of rangeIllegalArgumentException - if elements or size is negativepublic static int[] specificCombination(int elements,
int size,
double combination)
For example, you have 5 elements and want 3 of them. There are 10 combinations for this. The exact combinations can be ordered as:
012, 013, 014, 023, 024, 034, 123, 124, 134, 234. Combination number 4 is then 023,
so specificCombination(5, 3, 4) will return the array { 0, 2, 3 }
elements - number of elements you havesize - number of elements you want to pickcombination - the combination number you want to pick. 1 <= combinationNumber <= nCr(elements, size)0 <= value < elementsIllegalArgumentException - if combinationNumber is out of rangeIllegalArgumentException - if elements or size is negativeCopyright © 2014. All rights reserved.