Good Day
I know about how Factorial Number System is useful to find permutations and also find the the index of a permutation.
For example, permutation [1, 3, 4, 0, 2] has index (0 - based) 1 \cdot 4! + 2 \cdot 3! + 2 \cdot 2! + 0 \cdot 1! + 0 \cdot 1! = 40 where the constant is the index (0 - based) of the number in the unused numbers.
However, what if the arrangement contains repetitions. Consider [0, 0, 1, 1, 2, 2]. Now arrangement [2, 2, 1, 1, 0, 0] should have index \frac{6!}{2! \cdot 2! \cdot 2!} - 1 = 89, but if I go the usual way and consider the index in only the distinct unused numbers, I get 2 \cdot 5! + 2 \cdot 4! + \cdots which is already larger than 89. Even doing 2 \cdot \frac{120}{2 \cdot 2} + 2 \cdot \frac{24}{2 \cdot 2} + 1 \cdot \frac{6}{2} + 1 \cdot \frac{2}{2} gives 76.
Thus, is there a simple way to extend this system for repetitions, so that given an array of possibly non-distinct numbers, I can find the lexicographic index of the arrangement and from the (lexicographic) index, find the arrangement without casework?
Thanks