File: comb.5c

package info (click to toggle)
nickle 2.47-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,112 kB
  • ctags: 3,255
  • sloc: ansic: 30,401; yacc: 1,843; sh: 865; lex: 838; makefile: 202
file content (27 lines) | stat: -rw-r--r-- 461 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * Basic combinatorics
 * Copyright © 1995-2001 Bart Massey.
 * All Rights Reserved.  See the file COPYING in this directory
 * for licensing information.
 */

namespace Comb {

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

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

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

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

}