I have an array of 144 elements (integer numbers) and I want to find all possible permutations in Matlab. BUT the "problem" is that all these integer numbers can only have five different values: 11, 22, 33, 44 and 55 (the values do not really matter but anyway) and therefore changing, let's say, two 11's with each other does not make a new permutation. What I want is to find ONLY the unique permutations.
Matlab has the function perms
which can find all possible permutations and put them in a table. But since it finds ALL possible permutations and not only the unique ones, it does not work in my case because the outcome-table would have 144! rows which is too much and makes my machine (i7 cpu, 8gb ram) run out of memory. If perms
worked, I could then keep only the unique rows, which, if I am not wrong, should be 144!/n(11)!*n(22)!*n(33)!*n(44)!*n(55)!, where n(p) = times that number p appears and n(11)+n(22)+n(33)+n(44)+n(55)=144.
Is there any way to either make perms
work with an array of 144 elements work or even better a way to find only the necessary permutations? Another solution would be to be able to get all the 144! permutations without storing them in a table (I will use them one-by-one as they are produced). But I don't know how to do any of the above.
======================================
P.S.: I have also tried uint8
in order to try and keep perms
from consuming too much memory but it was not enough.
P.S.2: Since 144! is A LOT larger than 144!/n(11)!*n(22)!*n(33)!*n(44)!*n(55)!, a solution that finds only the necessary permutations would be better but please reply even if you have an idea on how to find all possible permutations and then I can keep the unique ones
P.S.3: I am not sure if I should call "permutations" or "combinations"what I am looking for because in a way it is both. Anyway, I decided to call them permutations in my question.