How may random unique combinations a 4x4 matrix can make

1.9k Views Asked by At

Let's say we have a matrix (grid) of 4x4 that has values from 0 to 15 in it.

    0  1  2  3
a = 4  5  6  7
    8  9  10 11
    12 13 14 15

If this array is randomized or shuffled how many unique combination can it make?

For example:
By unique I mean let's say 10 in the matrix a above is at 3x3 and in an attempt of a shuffle of the whole matrix, only 10 position shuffled with let's say 15 (10 is at the place 15 is and vice versa) so the new position fo 10 is now 4x4 and the matrix will look like this:

    0  1  2  3
b = 4  5  6  7
    8  9  15 11
    12 13 14 10

Now, b is a unique combination of a 4x4 matrix a. So, like that how many unique combinations can array a can have?

2

There are 2 best solutions below

1
On

I'd say $16!=16\times15\times\cdots\times2\times1$.

5
On

If you reduce from $4 \times 4$ to $16 \times 1$ with index from $1\ -> 16$, we can make a calculation like this.

With set of number can choose from $0$ to $15$

Choose a number for index $1$, we have $16$ choices

Choose a number for index $2$, we have $15$ choices (cause it has to be different with index $1$)

Choose a number for index $3$, we have $14$ choices (cause it has to be different with index $1$ and $2$)

And so on.

So, the number of choices will be $16 \times 15 \times 14 \times ... \times 1$ or it can be simplified is $16!$ according to the counting theory.

Note that, every time you select a number to fill in an index, it will be different from other index, so when you complete all $16$ choices, you will have an unique result.

Another way to approach this problem is, $4 \times 4 $ matrix has $16$ places to fill.

Let start with $0$, how many places you can put $0$ into the matrix? It's clearly $16$ cause our matrix is empty now.

Continue with $1$, our matrix right now is containing $0$, which means, you can not put $1$ at the same place as $0$. So how many places does the matrix left? It's $15$

You keep do it with $2, 3, 4, ..., 15$ and with the counting theory, you will have same result is $16!$.

EDIT: I found it, in Python, you can check the answer with some line of code like this:

import itertools

a = set(itertools.permutations([*your set here*]))

print(len(a))

But as I've tried, Python can not execute the answer if the set is big.