I want to create a list of 32 values such that from {a,b}
I can generate
{{a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b},
{a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,b,a,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b},...,
{b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a}}
(that's exactly 16 a's and 16 b's in each array, with repeats allowed).
I have tried Select[Tuples[{a,b},32],Count[##,a]==16]
, but get an error that "The length of the output of Tuples[{a,b},32] should be a machine integer."
The problem as I see it is that Tuples
is generating a lot of unneeded cases for my problem and the computer can't handle such a large number (and it would take a really long time even if it could).
I did a study of the timing of running some lower length arrays and assuming that the scaling stays linear (like it did for some of the larger numbers) it would take nearly 7 hours.
EDIT: I have the answer, but it won't let me post it, because I am new. So here it goes:
Building off of Kuba's suggestion, I came up with an answer that works for my problem. Sorry if I was unclear. I built a list and then made every permutation of the list until all elements were switched. It is easy enough to make sure it goes through the switch and then back to the original (thus generating every possible combination without eliminating repeats).
list = Join @@ (ConstantArray[#, 16] & /@ {a, b});
For[c = 1, c < 17, c++,
For[d = 17, d <= 33 - c, d++,
new = Permute[list, Cycles[{{c, d}}]];
];
list = new
];
Hopefully this will help someone else!