The following code is a very cut down version of what I am working with in terms of size. I have restricted the range of numbers to a max of 42, in my version it is 118, also the number of lists are over 11 million, for this demonstration I have kept them to a max of 400. The object is to select a subset of lists such that the combined set of lists contain all the integers 1 to 118, once only.
I am asking if there are any built in functions that would achieve what my program is doing, or if anyone can suggest an alternate approach. Solutions are found using the example code, but in my larger version it can take a few minutes to do just one pass and I have never got any better than 4 missing numbers.
There may not even be a solution, any help would be appreciated.
an = Complement[Range[42], {3, 18}]; a =
Table[Sort[RandomSample[an, 8]], {i, 1, 100}]; b =
Table[Sort[RandomSample[an, 6]], {i, 1, 100}]; c =
Table[Sort[RandomSample[an, 4]], {i, 1, 100}]; d =
Table[Sort[RandomSample[an, 2]], {i, 1, 100}]; e = Join[a, b, c, d];
big = Length[an]; Monitor[
Do[rs = RandomSample[e, 1]; t = {rs}; b = t; temp = e;
While[Length[b] > 0,
b = Select[temp, Length[Intersection[Flatten[t], #]] == 0 &];
If[Length[b] == 0, Goto[end]]; tt = RandomSample[b, 1];
t = Insert[t, tt, -1]; temp = b]; Label[end];
missing = Complement[an, Flatten[t]];
If[Length[missing] <= big, big = Length[missing];
Print[Length[missing], " , ", missing]; Print[t]], {w, 1,
1000}], {w, Length[temp]}]