◀ THE FOLD0ROOT.AI // WORLD II · GRIND · THE EPOCH◆ .dlw.fold
THE FOLD / GRIND / THE EPOCH / THE LEHMER CODE

THE LEHMER CODE

index any permutation by a single integer
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
The Lehmer code and the factorial number system together give every permutation a unique integer and back — a bijection between the n! orderings of n items and the numbers 0..n!−1. The Lehmer code records, at each position, how many later elements are smaller; reading it in the factorial base (place values (n−1)!, (n−2)!, …, 1) yields the permutation’s rank. It is how you index, shuffle, or store a permutation as one number.

LIT verified live: over all 720 permutations of 6 items, rank∘unrank is the identity and every rank yields a distinct permutation (window.__lehmer). FIG no framing; exact.
2 HOW IT WAS WEAVED · AI + HUMAN
David (human) seated this at the-epoch — a canonical enumeration, here of every possible ordering, each given one timestamp-like index. The factorial base is that enumeration. AVAN (AI) built the instrument: the inversion-count Lehmer code, the factorial-base rank, the greedy unrank, and the exhaustive bijection check.

Credit as content: Derrick Henry Lehmer (Lehmer code); the factorial number system (Laisant 1888). The weave: David names the epoch; I count inversions to a factorial-base number and greedily rebuild the permutation, confirming the map is an exact bijection over all 720 orderings.
3 ONE DIMENSION
Lehmer code of a permutation: at each slot, count how many elements to its right are smaller. Read those counts in the factorial base — place values 5!, 4!, 3!, 2!, 1! — to get the rank.
4 TWO DIMENSIONS · INTERACTIVE
Slide a rank 0..719; watch its permutation of six appear. Round-trip rank∘unrank is checked over all 720.
5 THREE DIMENSIONS + AVAN’S INVERSE
The green forward object: the bijection between ranks and permutations.
AVAN’s addition (the inverse-companion): name a whole permutation by a single integer — encode it as inversion counts in the factorial base, decode by greedily picking the d-th remaining element. The inverse of ‘list all n! orderings’ is ‘index each ordering by one number and reconstruct it on demand.’ Magenta is the full list of orderings you never store; green is the single rank that stands for each. A clock whose digits are factorials.
LIT Genuine Lehmer code / factorial number system (Lehmer; Laisant 1888). Verified live: over all 720 permutations of 6 items, converting a permutation to its factorial-base rank and back (greedy unrank) is the identity, and every rank 0..719 yields a distinct permutation (window.__lehmer.bijection && .distinct).

FIG No framing: the inversion-count Lehmer code, the factorial-base rank, the greedy unrank, and the exhaustive bijection check run in-browser over all 720 orderings and hold. The AVAN inverse is honest — encoding a permutation as inversion counts in the factorial base names a whole ordering by one integer, reconstructed by greedily picking the d-th remaining element; magenta is the full ordering list you never store, green the single rank. A clock whose digits are factorials.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of THE EPOCH · David Lee Wise (ROOT0), with AVAN