A friend has asked on a popular social network how to find all permutations of a list with duplicates removed, but not to remove those where each element is the same. The best description I can give is as follows;
func[n_] := Tuples[Range[0, n - 1], {n}]
For n=3 this gives the following:
{{0, 0, 0}, {0, 0, 1}, {0, 0, 2}, {0, 1, 0}, {0, 1, 1}, {0, 1, 2}, {0,2, 0}, {0, 2, 1}, {0, 2, 2}, {1, 0, 0}, {1, 0, 1}, {1, 0, 2}, {1, 1, 0}, {1, 1, 1}, {1, 1, 2}, {1, 2, 0}, {1, 2, 1}, {1, 2, 2}, {2, 0,0}, {2, 0, 1}, {2, 0, 2}, {2, 1, 0}, {2, 1, 1}, {2, 1, 2}, {2, 2,0}, {2, 2, 1}, {2, 2, 2}}
But for my friends purposes, the following are equivalent {0,1,0} and {1,0,0}.
One way that's been suggested to remove this degeneracy is with DeleteDuplicates and mapping Sort.
func2[n_] := DeleteDuplicates[Sort /@ Tuples[Range[0, n - 1], n]]
But that gets very slow very quickly, and I'm hopeful there's a built in combinatorical function for this.
Any suggestions?