Content deleted Content added
Mastergreg82 (talk | contribs) |
Mastergreg82 (talk | contribs) |
||
Line 35:
\end{matrix}
</math>
where the final line is the Lehmer code (at each line
For decoding a Lehmer code into a permutation of a given set, the latter procedure may be reversed: for each entry ''x'', in order from right to left, correct the items to its right by adding 1 to all those (currently) greater than or equal to ''x''; finally interpret the resulting permutation of {0, 1, … {{math|''n'' − 1}}} as sequence numbers (which amounts to adding 1 to each entry if a permutation of {1, 2, … ''n''} is sought). Alternatively the entries of the Lehmer code can be processed from left to right, and interpreted as a number determining the next choice of an element as indicated above; this requires maintaining a list of available elements, from which each chosen element is removed. In the example this would mean choosing element 1 from {A,B,C,D,E,F,G} (which is B) then element 4 from {A,C,D,E,F,G} (which is F), then element 0 from {A,C,D,E,G} (giving A) and so on, reconstructing the sequence B,F,A,G,D,E,C.
|