Skip to content

ToLehmerCode ​

Entry i counts the later entries smaller than p(i).

ToLehmerCode(Permutation)Entry i counts the later entries smaller than p(i).
Typed signatures
TypePackageApplies
(permutation) -> permutation_inversioncombinatoricsalways

Domain: Combinatorial maps

Details
  • Takes a Permutation and returns a PermutationInversion — a typed map, so a wrong carrier is a type error rather than a wrong answer.
  • Its total is the inversion count, which is the Lehmer code's whole point.

Examples

Basic #

the one-line word 231231

live ↗
InToLehmerCode(Permutation⁡([2,3,1]))\mathrm{ToLehmerCode}({\operatorname{Permutation}}([2, 3, 1]))OutPermutationInversion⁡([1,1,0]){\operatorname{PermutationInversion}}([1, 1, 0])
About
Examples1
CrosswalkWikipediaWikidataRosetta Code