Add distinct_permutations function