I'm trying to find a bijective mapping between a permutation and an index. The permutation refers to a 4-tuple of integers.
Tuples consist of $(a,b,c,d)$ such that $a,b,c,d \in [1;15]$ with $a \leq b \leq c \leq d$. For instance, these are possible:
0,0,0,00,2,7,88,9,15,15
And these, for instance, are not possible:
1,0,0,00,1,2,1
I would like to map these tuples to an index and back. As an example:
0,0,0,0$\leftrightarrow 0$0,0,0,1$\leftrightarrow 1$- ...
0,0,0,15$\leftrightarrow 15$0,0,1,0$\leftrightarrow 16$- ...
6,15,15,15$\leftrightarrow k$7,7,7,7$\leftrightarrow k+1$- ...
15,15,15,15$\leftrightarrow 3876$ (19 choose 4)
The order given above is not the only one, I am perfectly fine with any bijective mapping as long as it is not too computationally expensive. Can you help me find a formula?
Some background: I'm using this idea to compress sorted lists of integers. Right now I use a loopup table for translation, but it is rather large, so I am hoping to find a way with only rather elementary calculations. (But just out of curiousity, I would also love to see how this can be generalized to different numbers of elements and larger value ranges.)
The number 3876 (total number of valid combinations) is from this question, I also confirmed it experimentally.