I need to find all possible ways to combine k
amount of balls from n
types of balls.
Let's say if there are 3 types of balls and I want to take 2, result I want is:
1 1
1 2
1 3
2 2
2 3
3 3
I am trying to do it with the following line:
unique(nchoosek(repmat(1:n, 1, n), k), 'rows')
I get:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
How to do find all combinations with repetitions but without duplicates of same numbers?