Tool to calculate the rank of a permutation of a set. The permutation's rank is the number associated with it in the order of generation of the permutations.

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!

From the list of all possible permutations of a set (or arrangements), it is possible to sort this index in ascending order. The rank of a permutation is the position of that if in the sorted list.

Thus, the permutationBAC is at rank number 2 (starting at 0)

How to calculate the rank of a permutation?

Since it seems difficult to list all permutations when there are many items. There is a mathematical method to perform this calculation.

Take a permutation $ P $ in the set $ E $ of size $ t $.

Example: The permutationB,A,C from the initial set A,B,C of size $ t = 3 $

For each letter, calculate the position $ p $ in the set $ E $, calculate $ s = p \times (t-1)! $ and remove the letter from the set $ E $ (size $ t $ decreases). The sum of $ s $ is the rank of the permutation.

Example:B is in position $ 1 $ in ABC, $ s_B = 1 \times 2! = 2 $ A is in position $ 0 $ in AC, $ s_A = 0 \times 1! = 0 $ C is in position $ 0 $ in C, $ s_C = 0 \times 0! = 0 $ BAC is at permutation rank $ s_B + s_A + s_C = 2 + 0 + 0 = 2 $

Source code

dCode retains ownership of the online "Rank of a Permutation" source code. Except explicit open source licence (indicated CC / Creative Commons / free), the "Rank of a Permutation" algorithm, the applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or the "Rank of a Permutation" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) and all data download, script, copy-paste, or API access for "Rank of a Permutation" are not public, same for offline use on PC, tablet, iPhone or Android ! Remainder : dCode is free to use.

Need Help ?

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

Questions / Comments

Thanks to your feedback and relevant comments, dCode has developed the best 'Rank of a Permutation' tool, so feel free to write! Thank you!

Thanks to your feedback and relevant comments, dCode has developed the best 'Rank of a Permutation' tool, so feel free to write! Thank you!