I gather from this question that there is no primitive to build unordered tuples. That is, I want to do the equivalent of the following:
Union[Sort /@ Tuples[Range[9], {3}]]
to construct tuples of length 3 from Range[9], but considering (for example) {1,2,3} and {2,3,1} to be the same. The construct above clearly will not work if we replace 3 by, say, 20. Here is another approach:
f[lst_] := Flatten[Map[Table[Append[#, i], {i, Last@#, 9}] &, lst], 1];
Nest[f, Table[{i}, {i, Range[9]}], 2]
This has much better performance. But still, if 2 is replaced by 20, it takes almost two minutes on my computer. Is there a better approach?
Subsets[Range[9], {3}]? – Szabolcs Feb 02 '17 at 16:01Subsetsand it finally let me in. See my (second) answer below. – Mr.Wizard Feb 03 '17 at 01:00