experimental - not exact but allows large values float (4 bits) works till n = 125 for all k double (8 bits) works till n = 1020 for all k
| 279 | // float (4 bits) works till n = 125 for all k |
| 280 | // double (8 bits) works till n = 1020 for all k |
| 281 | double dcombinations(uint16_t n, uint16_t k) |
| 282 | { |
| 283 | if ((k == 0) || (k == n)) return 1; |
| 284 | if (k < (n-k)) k = n - k; // symmetry |
| 285 | double rv = n; |
| 286 | uint16_t p = 2; |
| 287 | for (uint16_t i = n-1; i > k; i--) |
| 288 | { |
| 289 | rv *= i; |
| 290 | rv /= p; |
| 291 | p++; |
| 292 | } |
| 293 | return rv; |
| 294 | } |
| 295 | |
| 296 | |
| 297 | // recursive (mind your stack and time) |