Suppose I have $n$ numbers $\{1,2,\cdots,n\}$, is there a very quick way of generating $k$-combinations using Mathematica?
Asked
Active
Viewed 92 times
3
1 Answers
3
In the answer below n=3 and k=2
Tuples[{1, 2, 3}, 2]
Compare to SubSets
Subsets[{1, 2, 3}, 2]
Edit: many thanks to @BobHanlon for suggesting:
Subsets[{1, 2, 3}, {2}]
bmf
- 15,157
- 2
- 26
- 63
-
4
-
@BobHanlon Can these subsets be generated iteratively instead of all at once? – licheng Nov 30 '22 at 08:11
-
1



Subsets. – JimB Nov 30 '22 at 00:00Range[n]={1, 2, ... , n}is useful for generating the list of numbers in the first place. – thorimur Nov 30 '22 at 02:42