Hoa central
Static Public Member Functions | List of all members
Hoa\Math\Combinatorics\Combination\Combination Class Reference

Static Public Member Functions

static Γ ($n, $k, $withoutZero=false)
 

Detailed Description

Class .

Some functions related to combinatorics.

Definition at line 49 of file Combination.php.

Member Function Documentation

static Hoa\Math\Combinatorics\Combination\Combination::Γ (   $n,
  $k,
  $withoutZero = false 
)
static

Γ^n_k denotes the set of k-uples whose sum of elements is n. For example: Γ^3_2 = {(2, 0, 0), (1, 1, 0), (1, 0, 1), (0, 2, 0), (0, 1, 1), (0, 0, 2)}. For any k-uple γ and any α in {1, …, k}, γ_α denotes the α-th element of γ.

Parameters
int$nn.
int$kk.
bool$withoutZeroDo not produce solutions with a zero inside.
Returns
array

Definition at line 63 of file Combination.php.

64  {
65  if (0 === $n) {
66  return [];
67  }
68 
69  $out = [];
70  $tmp = null;
71  $i = 0;
72  $o = array_fill(0, $n, 0);
73  $o[0] = $k;
74 
75  while ($k != $o[$i = $n - 1]) {
76  if (false === $withoutZero || !in_array(0, $o)) {
77  $out[] = $o;
78  }
79 
80  $tmp = $o[$i];
81  $o[$i] = 0;
82 
83  while ($o[$i] == 0) {
84  --$i;
85  }
86 
87  --$o[$i];
88  $o[$i + 1] = $tmp + 1;
89  }
90 
91  if (false === $withoutZero || !in_array(0, $o)) {
92  $out[] = $o;
93  }
94 
95  return $out;
96  }

The documentation for this class was generated from the following file: