I had asked this question before but I guess I did not make the question clear enough and I apologize for that. Here is the problem: Tuples
gives me more data than I want. A very bright user gave me a solution to restrict the output using a mechanism of filtering results as they are selected by his algorithm. The problem was even though it was efficient, it could not render data very well even on a machine with a lot of memory. Memory was the bottleneck and nothing else. It also tuples from all the lists and puts them in any of the positions. So let me present the problem hopefully more clearly, with some actual data I am trying to analyze.
Suppose the following, I have the following lists:
a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 21, 22, 23, 25, 26, 28}
b = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31, 33, 37, 41}
c = {6, 10, 13, 14, 15, 16, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 35, 37, 39}
d = {17, 19, 25, 30, 31, 33, 34, 35, 36, 38, 44}
e = {31, 41, 45, 47}
f = {23, 26, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 53}
What I am trying to achieve:
A tuple of length of 6 integer digits
The first digit can only be a tuple of list a, second digit can only be tupled from list b, and so on.
No number in any of the tupled outputs should be the same from any list, for example, {2,2,25,25,31,31}
is not a desired combination and should be excluded.
Order does not matter in this problem and should be excluded, for example, {2, 1, 10, 9, 42, 41}
would be considered the same as {1, 2, 9, 10, 41, 42}
and would be uneeded.
Obviously we have a large set of possible combinations, and as previously mentioned, M! loves to use memory and is not at all processor dependent, so limiting the memory footprint would be a priority.
Notice that the lists are of different lengths.
For large numbers of combinations, M! has difficulty rendering such a potentially large dataset on even a highend consumer grade computer, it would probably be advantageous to write these out to a text file as they are generated so the data can be viewed with an external text editor like Ultraedit.
Hope this is a detailed enough explaination and someone can share their thoughts! Thanks in advance!
Clear[unique]; SetAttributes[unique, Orderless]; DeleteDuplicates[ Select[(unique @@ # &) /@ Tuples[{a, b, c, d, e, f}], Length[#] == 6 &]]
requires 3 GB RAM and 58 seconds on my two-year old low-end workstation. (It finds 5,266,239 tuples.) $\endgroup$