@Test public void testCombination() { logger.info("combination"); int n = 52; int k = 5; double expResult = 2598960.0; double result = Arithmetics.combination(n, k); assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH); }
public static double combination(int n, int k) { if(n<k) { throw new IllegalArgumentException("The n can't be smaller than k."); } double combinations=1.0; double lowerBound = n-k; for(int i=n;i>lowerBound;i--) { combinations *= i/(i-lowerBound); } return combinations; }
Arithmetics { public static double combination(int n, int k) { if(n<k) { throw new IllegalArgumentException("The n can't be smaller than k."); } double combinations=1.0; double lowerBound = n-k; for(int i=n;i>lowerBound;i--) { combinations *= i/(i-lowerBound); } return combinations; } }
Arithmetics { public static double combination(int n, int k) { if(n<k) { throw new IllegalArgumentException("The n can't be smaller than k."); } double combinations=1.0; double lowerBound = n-k; for(int i=n;i>lowerBound;i--) { combinations *= i/(i-lowerBound); } return combinations; }  }
Arithmetics { public static double combination(int n, int k) { if(n<k) { throw new IllegalArgumentException("The n can't be smaller than k."); } double combinations=1.0; double lowerBound = n-k; for(int i=n;i>lowerBound;i--) { combinations *= i/(i-lowerBound); } return combinations; }  static double factorial(int k); static double combination(int n, int k); }
Arithmetics { public static double combination(int n, int k) { if(n<k) { throw new IllegalArgumentException("The n can't be smaller than k."); } double combinations=1.0; double lowerBound = n-k; for(int i=n;i>lowerBound;i--) { combinations *= i/(i-lowerBound); } return combinations; }  static double factorial(int k); static double combination(int n, int k);  }