partial implementation of lexicographic permutations