(pool: T[], k: number)
| 113 | } |
| 114 | |
| 115 | function* combinations<T>(pool: T[], k: number): Generator<T[]> { |
| 116 | if (k === 0) { |
| 117 | yield []; |
| 118 | return; |
| 119 | } |
| 120 | for (let i = 0; i <= pool.length - k; i++) { |
| 121 | for (const rest of combinations(pool.slice(i + 1), k - 1)) { |
| 122 | yield [pool[i], ...rest]; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Invert the affine map `x = base + coef·t`: find integer parameters `t` |