Search for a tool
Combination Rank

Tool for calculating the rank of a mathematical combination (or conversely, calculating a combination from a rank), that is, the position of a combination in the growing list of possible combinations generated.

Results

Combination Rank -

Tag(s) : Combinatorics

Share
Share
dCode and more

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!


Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!


Feedback and suggestions are welcome so that dCode offers the best 'Combination Rank' tool for free! Thank you!

Combination Rank

Rank from Combination Calculator



Combination from Rank Calculator




Answers to Questions (FAQ)

What is the rank of a combination? (Definition)

The rank of a combination corresponds to its position in the list of all possible combinations, sorted by ascending lexicographic order. On this page, dCode indexes the rank starting from $ 1 $.

Example: All combinations of $ 2 $ elements out of $ 4 $ are: $ (1,2), (1,3), (1,4), (2,3), (2,4), (3,4) $, thus, the combination $ (1,2) $ is of rank $ 1 $ and the combination $ (2,4) $ is of rank $ 5 $

How to calculate the rank of a combination?

For a combination of $ k $ elements denoted $ (c_1, c_2, \cdots, c_k) $ with $ 1 \le c_1 < c_2 < \cdots < c_k \le n $. The rank $ r $ of this combination among all the combinations of $ k $ elements chosen from $ n $ can be calculated without enumerating them using the formula: $$ r = \binom{n}{k} - \binom{n-c_1}{k} - \binom{n-c_2}{k-1} - \cdots - \binom{n-c_k}{1} $$

This formula is based on the counting of all combinations that are lexicographically larger than the combination studied.

Example: To calculate the rank of the combination $ (1,3) $ among the combinations of 2 out of 4 $ \binom{4}{2} $ is to take $ n = 4, k = 2, c_1 = 1, c_2 = 3 $ and calculate $$ \binom{4}{2} - \binom{4-1}{2} - \binom{4-3}{2-1} = 6 - 3 - 1 = 2 $$ so $ (1,3) $ is in rank $ 2 $.

How to calculate a combination from its rank?

This method allows calculating the lexicographically minimal combination of size $ k $ associated with a rank $ r $, with a rank indexed starting from $ 1 $.

The algorithm is based on the inverse principle of rank calculation: it consists of gradually reconstructing the elements of the combination using binomial coefficients.

For a combination of size $ k $ and a rank $ r $:

1 - Initialize an empty list for the combination

2 - For each position $ j $ ranging from $ k $ to $ 1 $, determine the largest integer $ c $ such that $ \binom{c}{j} < r $

3 - Add $ c + 1 $ at the beginning of the combination.

4 - Update the rank: $ r = r - \binom{c}{j} $

5 - Repeat steps 2, 3, and 4 for each value of $ j $, decrementing $ j $ by $ 1 $ at each iteration, until reaching $ j = 1 $

Example: Calculate the size combination $ 2 $ corresponding to the rank $ r = 5 $:
for $ j = 2 $: $ \binom{2}{2} = 1 < 5 $, $ \binom{3}{2} = 3 < 5 $, $ \binom{4}{2} = 6 \ge 5 $, so $ c = 3 $, add $ 4 $ to the combination, new rank $ r = 5 - 3 = 2 $.
For $ j = 1 $: $ \binom{1}{1} = 1 < 2 $, $ \binom{2}{1} = 2 \ge 2 $, so $ c = 1 $, add $ 2 $ to the combination.
The resulting combination is $ (2,4) $, which is indeed the rank $ 5 $ combination among those of size $ 2 $.

Source code

dCode retains ownership of the "Combination Rank" source code. Any algorithm for the "Combination Rank" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Combination Rank" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Combination Rank" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.

Cite dCode

The content of the page "Combination Rank" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).

Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).

To cite dCode.fr on another website, use the link: https://www.dcode.fr/combination-rank

In a scientific article or book, the recommended bibliographic citation is: Combination Rank on dCode.fr [online website], retrieved on 2026-04-14, https://www.dcode.fr/combination-rank

Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Questions / Comments

Feedback and suggestions are welcome so that dCode offers the best 'Combination Rank' tool for free! Thank you!


https://www.dcode.fr/combination-rank
© 2026 dCode — The ultimate collection of tools for games, math, and puzzles.
â–˛  
Feedback