Lehmer code
= Lehmer code
{c}
For a <permutation> $p_0,\ldots,p_{n-1}$ of $n$ ordered distinct values, its Lehmer code has entries $c_i=\#\{j>i:p_j<p_i\}$. Its zero-based <lexicographic order> rank is $\sum_{i=0}^{n-1}c_i(n-1-i)!$. Each entry chooses among the still unused values; the <factorial> weights count all completions with a smaller choice at the first differing position.