@classmethod
    def unrank_lex(self, size, rank):
        """
        Lexicographic permutation unranking.

        Examples
        ========

        >>> from sympy.combinatorics.permutations import Permutation
        >>> Permutation.print_cyclic = False
        >>> a = Permutation.unrank_lex(5, 10)
        >>> a.rank()
        10
        >>> a
        Permutation([0, 2, 4, 1, 3])

        See Also
        ========

        rank, next_lex
        """
        perm_array = [0] * size
        psize = 1
        for i in range(size):
            new_psize = psize*(i + 1)
            d = (new_psize % rank) // psize
            rank -= d*psize
            perm_array[size - i - 1] = d
            for j in range(size - i, size):
                if perm_array[j] > d - 1:
                    perm_array[j] += 1
            psize = new_psize
        return _af_new(perm_array)

    # global flag to control how permutations are printed
    # when True, Permutation([0, 2, 1, 3]) -> Cycle(1, 2)
    # when False, Permutation([0, 2, 1, 3]) -> Permutation([0, 2, 1])
dataset/ETHPy150Open sympy/sympy/sympy/combinatorics/permutations.py/Permutation.unrank_lex/swapped operands of `%`