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

Function combPascal

libraries/statHelpers/statHelpers.cpp:322–331  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

320// works for n = 0..30 for all k (but takes a lot of time)
321// educational purpose
322uint32_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/////////////////////////////////////////////////

Callers 1

unittestFunction · 0.85

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.68