Suppose we have 2 x N
matrix in form of
A=| a1 a2 ... aN |
| b1 b2 ... bN |
There are 2^N combinations how the row can be rearranged. I'd like to find matrix B
containing all the combinations.
%% N=2
B=|a1 a2|
|a1 b2|
|b1 a2|
|b1 b2|
%% N=3
B=|a1 a2 a3|
|a1 a2 b3|
|a1 b2 a3|
|a1 b2 b3|
|b1 a2 a3|
|b1 a2 b3|
|b1 b2 a3|
|b1 b2 b3|
This is very similar to the tables used for learning basics of Boolean algebra (ai=0,bi=1).
The question may be expanded to creating M^N x N
matrix from M x N
.