MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / combinations64

Function combinations64

libraries/statHelpers/statHelpers.cpp:262–275  ·  view source on GitHub ↗

works for n = 0..61 for all k

Source from the content-addressed store, hash-verified

260
261// works for n = 0..61 for all k
262uint64_t combinations64(uint16_t n, uint16_t k)
263{
264 if ((k == 0) || (k == n)) return 1;
265 if (k < (n-k)) k = n - k; // symmetry
266 uint64_t rv = n;
267 uint8_t p = 2;
268 for (uint8_t i = n-1; i > k; i--)
269 {
270 // overflow detect here ?
271 rv = (rv * i) / p;
272 p++;
273 }
274 return rv;
275}
276
277
278// experimental - not exact but allows large values

Callers 1

unittestFunction · 0.85

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.68