very slow double recursive way by means of Pascals triangle. works for n = 0..30 for all k (but takes a lot of time) educational purpose
| 320 | // works for n = 0..30 for all k (but takes a lot of time) |
| 321 | // educational purpose |
| 322 | uint32_t combPascal(uint16_t n, uint16_t k) |
| 323 | { |
| 324 | if (k > (n-k)) k = n - k; // symmetry |
| 325 | if (k > n ) return 0; |
| 326 | if (k == 0) return 1; |
| 327 | if (n < 2) return 1; |
| 328 | uint32_t rv = combPascal(n-1, k-1); |
| 329 | rv += combPascal(n-1, k); |
| 330 | return rv; |
| 331 | } |
| 332 | |
| 333 | |
| 334 | ///////////////////////////////////////////////// |