[Math] Possible permutations of a grid

permutationsrecreational-mathematics

I hope this is the correct place to post this, as I don’t study maths. But I do need help calculating the possible permutations of a grid based game I’m currently programming. This isn’t to help out with the game logic, but rather to help me understand how many different combinations of each puzzle I can get by randomising the placement of the tiles.

I think that to someone with a good understanding of maths, this should be a pretty basic problem to solve. I would give it a shot myself, but I didn’t study further maths and I really want a correct answer/algorithm.

Okay so this is the scenario:

I have a 5×5 grid of coloured tiles. There are 5 different colours of tiles. By default, the tiles are ordered into rows of 5. My question is, if every tile can go to any position in the 5×5 grid, how many possible permutations of the grid are there? (also taking into account that tiles of the same colour count as the same tile, so 'red tile A’ is exactly the same as ‘red tile B’ as far as the game mechanics are concerned)

It would be useful to know what you think the permutations figure is for this specific grid but also the calculation you used to arrive at that answer. The reason for this is that the size of the grid may change in the future and I’d like to be able to use the same algorithm to calculate its permutations. It's also likely that I will have other layouts which aren't arranged into rows, and may have different quantities of each block, so if anyone could point me in the right direction with this, it would be greatly appreciated!

Thanks for any advice!!

Below is an example screenshot of what I mean, you can ignore the numbers as they are just for debugging purposes.

enter image description here

Best Answer

If the tiles were distinguishable, we could permute them in $25! $ ways, since for the first tile there would be $25 $ places, for the second one $24 $ etc... But now we can still interchange tiles of a given color with themselves (and leave the permutation "the same"). For instance the red tiles can be permuted between eachother in $5!$ ways. Therefore the final answer should be (divide by $5!$ for each color):

$$\frac {25!}{5! 5! 5! 5! 5!}=\frac{(5^2)!}{(5!)^5}=623360743125120$$

Usind the same reasoning, for an $n \times n$ grid we get:

$$\frac {(n^2)!}{(n!)^n}$$

Now note that the total number of permutations has nothing to do with the grid being a square, so we can generalise even further, to a grid with $k$ tiles and number of tiles per colour $n_1,\cdots,n_m$ (with $n_1+\cdots+n_m=k$). Then we get:

$$\frac{k!}{n_1!*\cdots *n_m!}$$ different permutations.

Related Question