bdCombinat: A command-line utility to compute combinatorics
bdCombinat.exe is a standalone command-line program that computes the values of factorial(n),
binomial(n,k) and permutations(n,k) using arbitrary large nonnegative integers.
Updated: 30 March 2026 to version 1.1.
For the theory see Combinatorics: combinations and permutations.
Usage | Examples | Download | To install | About bdCombinat.exe | Source code | Contact us
Usage
Usage: bdCombinat [OPTIONS] <expression> OPTIONS: -q Quiet mode (only display result) -L display Licence conditions and exit -V display Version information and exit -h display this Help and exit The <expression> argument is a string representing a mathematical expression to evaluate. It supports: - Numbers: Non-negative integers (e.g., 5, 123). - Functions: - factorial(n): Computes n! (n must be >= 0). - binomial(n,k): Computes n choose k (n >= k >= 0). - permutations(n,k): Computes n permute k (n >= k >= 0). - Operators: Addition (+), subtraction (-), multiplication (*), division (/). - Parentheses: For grouping (e.g., (2+3)*4). Expressions are evaluated left-to-right with standard precedence (multiplication/division before addition/subtraction). Functions take precedence over operators. Invalid syntax or out-of-range values result in an error. Examples: `factorial(5)`, `binomial(10,3) + 2*3`. Division is *integer* division where the fractional part is discarded. Negative numbers raise an error, e.g. `2-5+10` is invalid.
Examples
> bdCombinat factorial(52) factorial(52)=80658175170943878571660636856403766975289505440883277824000000000000 > bdCombinat binomial(52,13) binomial(52,13)=635013559600 > bdCombinat -q binomial(52,13)*binomial(39,13)*binomial(26,13)*binomial(13,13) 53644737765488792839237440000 > bdcombinat -q factorial(52)/factorial(13)/factorial(13)/factorial(13)/factorial(13) 53644737765488792839237440000 > bdCombinat permutations(52,13) permutations(52,13)=3954242643911239680000 > bdCombinat permutations(52,13)/factorial(13) permutations(52,13)/factorial(13)=635013559600
Some of these examples are inspired by Bridge Hand Probability Analysis by Occasional Enthusiast. We recently took up the card game bridge again after a gap of many decades. We were curious about how to calculate the number of hands and discovered that our usual tools to compute binomials gave the wrong answer because the results "overflowed". So we wrote our own.
How many hands are there?
The number of ways 13 cards can be selected from 52: \[ \binom{52}{13} = 635013559600 \]
How many deals are there?
Consider each hand in turn. The first, North (say), selects 13 cards from 52, the second, selects 13 cards from the remaining 39 cards (after North’s selection). The third hand selects 13 cards from the remaining 26 cards. The final 13 cards go to the last hand. \[ \binom{52}{13} \times \binom{39}{13} \times \binom{26}{13} \times \binom{13}{13} = 53644737765488792839237440000 \]
Or, imagine laying out the 52 cards in every possible order and then taking the first 13 as the North (say) hand, the next 13 as the South hand, etc. This isn’t quite correct as it includes the card order within each hand. We don’t care about this order. To remove it, we can divide by the number of ways 13 cards can be ordered within a hand. The number of ways 52 cards can be ordered is 52!. The number of ways 13 cards can be ordered is 13!. This leads to the result of: \[ \frac{52!}{(13!)^4} = 53644737765488792839237440000 \] The number of ways 52 cards can be ordered is 52! \[ 52! = 80658175170943878571660636856403766975289505440883277824000000000000 \]
Download
This includes executables compiled for both Win32 and X64 platforms. (The 32-bit compilation should work on most Windows computers; the 64-bit version is there if you need it.)
To install
- Copy the file
bdCombinat.exeinto a directory on your PC's path, e.g. C:\Windows. - That's it!
- We recommend you set up a C:\Bin directory for files like this.
About bdCombinat.exe
bdCombinat.exe is written in ANSI C using our BigDigits library.
The executable is provided under the BSD-2-Clause license available at https://opensource.org/license/BSD-2-Clause.
For more information about computing permutations, combinations and factorials, see Combinatorics: combinations and permutations.
Revision History
- 2026-03-30: Version 1.1.
- Removed cut-off subtraction. It is now an error to get a negative result, e.g.
2-5+10is invalid. - Updated bdcombinatorics.c and t_bdCombinatorics.c to use latest features from BigDigits v2.7
- Removed cut-off subtraction. It is now an error to get a negative result, e.g.
- 2026-03-26: First release of version 1.0.
Source code
The core source code for the functions factorial(n),
binomial(n,k) and permutations(n,k):
Source code zipped: t_bdCombinatorics-1.0.1.src.zip (4 kB).
To compile using the MSVC command line
CL /TC /DNO_WINGUI t_bdCombinatorics.c bdcombinatorics.c bigd.c bigdigits.c /Fe:t_bdCombinatorics.exe
The /TC option treats all files as C source files, and the /DNO_WINGUI avoids the need to use Windows GUI tools.
If you don't use the NO_WINGUI macro, you'll need to make an explicit link to user32.lib using/link user32.lib.CL /TC t_bdCombinatorics.c bdcombinatorics.c bigd.c bigdigits.c /link user32.lib /Fe:t_bdCombinatorics.exe
To compile using gcc (this works in both MinGW32 and Debian Linux environments).
gcc t_bdCombinatorics.c bdcombinatorics.c bigd.c bigdigits.c -o t_bdCombinatorics
Note: as of 5 April 2026, this code is now incorporated into the latest version 2.3 of bdcalc - a calculator for large natural numbers.
Contact us
To contact us or comment on this page, please send us a message.
This page first published 26 March 2026. Last updated 7 April 2026

