choose function

int choose(
  1. int n,
  2. int r, {
  3. bool useCache = true,
})

Implementation

int choose(int n, int r, {bool useCache = true}) {
  if (useCache) {
    return chooseCached(n, r);
  }

  if (n < r) {
    return 0;
  }

  if (r == 0) {
    return 1;
  }

  var denom = range(start: 1, end: r + 1).fold<int>(1, (a, b) => a * b);
  var numer =
      range(start: n, end: n - r, step: -1).fold<int>(1, (a, b) => a * b);

  return numer ~/ denom;
}