Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > b7d4776776c8e4296a0951083113f920 > files > 10

nickle-2.69-2.fc13.i686.rpm

/*
 * Basic combinatorics
 * Copyright © 1995-2001 Bart Massey.
 * All Rights Reserved.  See the file COPYING in this directory
 * for licensing information.
 */

namespace Comb {

  public int perm(n, r) {
    return n! // r!;
  }

  public int choose(n, r) {
    return n! // (r! * (n - r)!);
  }

  public int binom(n, k) {
    int sum, i;

    sum = 1;
    for (i = 1; i <= k; i++)
	  sum += choose(n, i);
    return sum;
  }

}