ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Combinations.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
8 {
23  public static function withoutRepetition($numObjs, $numInSet)
24  {
25  try {
26  $numObjs = Helpers::validateNumericNullSubstitution($numObjs, null);
27  $numInSet = Helpers::validateNumericNullSubstitution($numInSet, null);
29  Helpers::validateNotNegative($numObjs - $numInSet);
30  } catch (Exception $e) {
31  return $e->getMessage();
32  }
33 
34  return round(Factorial::fact($numObjs) / Factorial::fact($numObjs - $numInSet)) / Factorial::fact($numInSet);
35  }
36 
51  public static function withRepetition($numObjs, $numInSet)
52  {
53  try {
54  $numObjs = Helpers::validateNumericNullSubstitution($numObjs, null);
55  $numInSet = Helpers::validateNumericNullSubstitution($numInSet, null);
58  $numObjs = (int) $numObjs;
59  $numInSet = (int) $numInSet;
60  // Microsoft documentation says following is true, but Excel
61  // does not enforce this restriction.
62  //Helpers::validateNotNegative($numObjs - $numInSet);
63  if ($numObjs === 0) {
64  Helpers::validateNotNegative(-$numInSet);
65 
66  return 1;
67  }
68  } catch (Exception $e) {
69  return $e->getMessage();
70  }
71 
72  return round(Factorial::fact($numObjs + $numInSet - 1) / Factorial::fact($numObjs - 1)) / Factorial::fact($numInSet);
73  }
74 }
static validateNumericNullSubstitution($number, $substitute)
Validate numeric, but allow substitute for null.
Definition: Helpers.php:51
static withRepetition($numObjs, $numInSet)
COMBIN.
static validateNotNegative($number, ?string $except=null)
Confirm number >= 0.
Definition: Helpers.php:69
static withoutRepetition($numObjs, $numInSet)
COMBIN.