I'll try to explain the problem clearly. I've a set of numbers such as {2,0,6,1,2,6}. This set can be seen as groups of 3 numbers, in this case the first group would be G1={2,0,6} and the second G2={1,2,6}; this also means that the number of numbers in the set is always divisible by 3. I want to find all the permutations of the numbers in the set but respecting the following limit:
In all the groups that can be created, the decimal number obtained by sticking together the 3 digits must be less than or equal to 253.
I'll show the procedure I followed to solve the problem with the set above.
I write the set starting by the smallest numbers: 0xx1xx , permutations=$\frac{4!}{2!2!}=6$
- 0xx21x perms=3
- 0xx22x perms=3
- 1xx0xx perms=6
- 1xx20x perms=3
- 1xx22x perms=3
- 20x1xx perms=3
- 20x21x perms=1
- 21x0xx perms=3
- 21x20x perms=1
- 22x0xx perms=3
- 22x1xx perms=3
Total=38
Basically I tried to generate successive patterns keeping the max generalization. I wrote a program that follows this procedure and its output was 38 as well.
Now, the problem occurs when the set is big, the set of the problem I have to deal with has 768 numbers and my program would take... ages I think. Using complementary permutations won't solve the issue either I think. Specifically, the set has 768 numbers and the frequencies are:
\begin{array}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|} \hline n & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\ \hline freq & 174 & 156 & 104 & 55 & 54 & 46 & 44 & 43 & 48 & 44\\ \hline \end{array}
I need to calculate the permutations with the limit described of this set. Any idea? If there's no way that this can be done in a reasonable amount of time, can I at least know how many digits would the number of permutations take (like $2*10^{463}$)? Thanks.
I was thinking, if the limit was 255, which is exactly "11111111" in binary, could I handle the problem by converting each group(the 3 digit decimal number) to binary and therefore having groups of 8bit? If I do so I'll have an intrinsic limit thanks to the binary code(0-255), then I'll only have to do permutations like this $$\frac{(8*256)!}{(frequency of 1)! * (frequency of 0)!}$$ Am I wrong?