# Subsets - Ranking / Unranking

#### Klaas van Aarsen

##### MHB Seeker
Staff member
I haven't really understood that part. Could you explain that further to me?
Consider the case $n=3$, so $(n-1)!=(3-1)!=2$.
$\begin{array}{ccccc} r & \pi(1) & [\pi(2),\pi(3)] & \pi'& r'\\ \hline 0 & 1 & [2,3] & [1,2] & 0\\ 1 & 1 & [3,2] & [2,1] & 1\\ 2 & 2 & [1,3] & [1,2] & 0 \\ 3 & 2 & [3,1] & [2,1] & 1 \\ 4 & 3 & [1,2] & [1,2] & 0 \\ 5 & 3 & [2,1] & [2,1] & 1 \\ \end{array}$

If we divide $r$ by $(n-1)!$ and add $1$, we get $\pi(1)$.
We also have that $r'=r\bmod (n-1)!$, from which we can deduce $\pi'$.
And in combination with $\pi(1)$, we can find $\pi$.

In the notes that I am looking at it is divided by $i$. So should it be divided by $i!$ ?
Yes, I believe so.