Greetings Delphian stackers.
I've searched through out the site, all the "permutation rank & unrank" related discussions and could not find the one that meets my needs.
In Delphi:
Having an array of:
Members: array [0..3] of Byte = (0,1,2,3);
If one want's to iterate through all distinct permutations composed by 3 elements, one can estimate that the result list will be composed by 24 lines, lexicographically ordered as:
0 012
1 013
2 021
3 023
4 031
5 032
6 102
7 103
8 120
9 123
10 130
11 132
12 201
13 203
14 210
15 213
16 230
17 231
18 301
19 302
20 310
21 312
22 320
23 321
One can calculate the size of the list by using a "n choose k" formula, where "n" stands for the number of members and "k" for the number of choices:
p(n,k) = n! / (n-k)!
p(4,3) = 4! / (4-3)! = (4 x 3 x 2 x 1) / (1 x 1) = 24
What i'm trying to figure out is how to, (without searching through the entire list):
By supplying the lexicographic rank, let's say "13", one can "unrank" and obtain the subset "203".
By supplying the subset "203" one can obtain the lexicographic rank "13".
Any help will be much appreciated.
Thank you for your time.