Given some number n
and set of values vals
, I want to obtain all the tuples/permutations of size n
for the values in vals
, but without any repeated tuples. So e.g. n=2
and vals={3,6}
should give
n = 2, vals = {0,1} --> { {0,0}, {0,1}, {1,1} }
n = 2, vals = {0,1,2} --> { {0,0}, {0,1}, {0,2}, {1,1}, {1,2}, {2,2} }
n = 3, vals = {0,1} --> { {0,0,0}, {0,0,1}, {0,1,1}, {1,1,1} }
n = 3, vals = {0,1,2} --> { {0,0,0}, {0,0,1}, {0,0,2}, {0,1,1}, {0,1,2}, {0,2,2}, {1,1,1}, {1,1,2}, {1,2,2}, {2,2,2} }
I've tried the following commands:
n = 2;
vals = {0, 1};
Tuples[vals, {n}] (* gives { {0, 0}, {0, 1}, {1, 0}, {1, 1} } *)
Permutations[vals, {n}] (* gives { {0, 1}, {1, 0} } *)
Subsets[vals, {n}] (* gives { {0, 1} } *)
Permutations
and Subsets
are incomplete. Tuples
contains all the right combinations, but also contains duplicates like {0, 1}
and {1, 0}
. Since I do not care about order, I'd like to remove those.
How do I achieve the behavior of Tuples
, but without duplicates?