3

My problem is to get the list of all combinations of length 3 where the first place can be 1,2; second place could be a,b; third place could be 1,2,3,4. So the output is should be like this: $\{\{1,a,1\},\{1,a,2\},\cdots,\{2,b,4\}\}$.

Marcus
  • 143
  • 6

1 Answers1

7

You want to use Tuples

Tuples[{{1, 2}, {a, b}, {1, 2, 3, 4}}]

Does what you want. Check out the documentation.

Cheers

AndreasP
  • 598
  • 4
  • 10
  • Yes it does the job, thanks! Could you please explain the rule a bit, like if I had length $n$, the first place has $K_1$ possibilities, 2nd place $K_2$ possibilities,...,$n$-th place $K_n$ possibilities? – Marcus Oct 17 '16 at 13:47
  • Aha sorry got it now. Thanks again! – Marcus Oct 17 '16 at 13:48