2
$\begingroup$

I have a list:

listaBase1 = {2, 1, 25, 6, 14, 4, 9, 19, 5, 23, 18, 10, 17, 12, 3, 20}

And I created sublists from this:

G1 = Subsets[listaBase1, {15}]

$\left( \begin{array}{ccccccccccccccc} 2 & 1 & 25 & 6 & 14 & 4 & 9 & 19 & 5 & 23 & 18 & 10 & 17 & 12 & 3 \\ 2 & 1 & 25 & 6 & 14 & 4 & 9 & 19 & 5 & 23 & 18 & 10 & 17 & 12 & 20 \\ 2 & 1 & 25 & 6 & 14 & 4 & 9 & 19 & 5 & 23 & 18 & 10 & 17 & 3 & 20 \\ 2 & 1 & 25 & 6 & 14 & 4 & 9 & 19 & 5 & 23 & 18 & 10 & 12 & 3 & 20 \\ 2 & 1 & 25 & 6 & 14 & 4 & 9 & 19 & 5 & 23 & 18 & 17 & 12 & 3 & 20 \\ 2 & 1 & 25 & 6 & 14 & 4 & 9 & 19 & 5 & 23 & 10 & 17 & 12 & 3 & 20 \\ 2 & 1 & 25 & 6 & 14 & 4 & 9 & 19 & 5 & 18 & 10 & 17 & 12 & 3 & 20 \\ 2 & 1 & 25 & 6 & 14 & 4 & 9 & 19 & 23 & 18 & 10 & 17 & 12 & 3 & 20 \\ 2 & 1 & 25 & 6 & 14 & 4 & 9 & 5 & 23 & 18 & 10 & 17 & 12 & 3 & 20 \\ 2 & 1 & 25 & 6 & 14 & 4 & 19 & 5 & 23 & 18 & 10 & 17 & 12 & 3 & 20 \\ 2 & 1 & 25 & 6 & 14 & 9 & 19 & 5 & 23 & 18 & 10 & 17 & 12 & 3 & 20 \\ 2 & 1 & 25 & 6 & 4 & 9 & 19 & 5 & 23 & 18 & 10 & 17 & 12 & 3 & 20 \\ 2 & 1 & 25 & 14 & 4 & 9 & 19 & 5 & 23 & 18 & 10 & 17 & 12 & 3 & 20 \\ 2 & 1 & 6 & 14 & 4 & 9 & 19 & 5 & 23 & 18 & 10 & 17 & 12 & 3 & 20 \\ 2 & 25 & 6 & 14 & 4 & 9 & 19 & 5 & 23 & 18 & 10 & 17 & 12 & 3 & 20 \\ 1 & 25 & 6 & 14 & 4 & 9 & 19 & 5 & 23 & 18 & 10 & 17 & 12 & 3 & 20 \\ \end{array} \right)$

And now I have another list:

listaBase2 = {1,25,23,2,14,3,5,7,8,11,13,15,16,21,22,24}

With another sublists:

G2 = Subsets[listaBase2, {15}]

$\left( \begin{array}{ccccccccccccccc} 1 & 25 & 23 & 2 & 14 & 3 & 5 & 7 & 8 & 11 & 13 & 15 & 16 & 21 & 22 \\ 1 & 25 & 23 & 2 & 14 & 3 & 5 & 7 & 8 & 11 & 13 & 15 & 16 & 21 & 24 \\ 1 & 25 & 23 & 2 & 14 & 3 & 5 & 7 & 8 & 11 & 13 & 15 & 16 & 22 & 24 \\ 1 & 25 & 23 & 2 & 14 & 3 & 5 & 7 & 8 & 11 & 13 & 15 & 21 & 22 & 24 \\ 1 & 25 & 23 & 2 & 14 & 3 & 5 & 7 & 8 & 11 & 13 & 16 & 21 & 22 & 24 \\ 1 & 25 & 23 & 2 & 14 & 3 & 5 & 7 & 8 & 11 & 15 & 16 & 21 & 22 & 24 \\ 1 & 25 & 23 & 2 & 14 & 3 & 5 & 7 & 8 & 13 & 15 & 16 & 21 & 22 & 24 \\ 1 & 25 & 23 & 2 & 14 & 3 & 5 & 7 & 11 & 13 & 15 & 16 & 21 & 22 & 24 \\ 1 & 25 & 23 & 2 & 14 & 3 & 5 & 8 & 11 & 13 & 15 & 16 & 21 & 22 & 24 \\ 1 & 25 & 23 & 2 & 14 & 3 & 7 & 8 & 11 & 13 & 15 & 16 & 21 & 22 & 24 \\ 1 & 25 & 23 & 2 & 14 & 5 & 7 & 8 & 11 & 13 & 15 & 16 & 21 & 22 & 24 \\ 1 & 25 & 23 & 2 & 3 & 5 & 7 & 8 & 11 & 13 & 15 & 16 & 21 & 22 & 24 \\ 1 & 25 & 23 & 14 & 3 & 5 & 7 & 8 & 11 & 13 & 15 & 16 & 21 & 22 & 24 \\ 1 & 25 & 2 & 14 & 3 & 5 & 7 & 8 & 11 & 13 & 15 & 16 & 21 & 22 & 24 \\ 1 & 23 & 2 & 14 & 3 & 5 & 7 & 8 & 11 & 13 & 15 & 16 & 21 & 22 & 24 \\ 25 & 23 & 2 & 14 & 3 & 5 & 7 & 8 & 11 & 13 & 15 & 16 & 21 & 22 & 24 \\ \end{array} \right)$

How do I know if there is any repetition in these two groups $G1$ and $G2$? And if there is a repetition, is there a way to show which list would be?

$\endgroup$

closed as unclear what you're asking by corey979, RunnyKine, user9660, Feyre, MarcoB Jan 3 '17 at 18:07

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ What exactly is a "repetition" here? Are you looking for a list that is common to both G1 and G2? (You can use Intersection[] for that.) $\endgroup$ – J. M. is away Jan 2 '17 at 17:57
  • $\begingroup$ @J. M. If there are any of these 32 lists that are repeated. $\endgroup$ – user45493 Jan 2 '17 at 18:15
  • $\begingroup$ Have you seen Gather[], then? $\endgroup$ – J. M. is away Jan 2 '17 at 18:30
  • $\begingroup$ Ok. I will see this. $\endgroup$ – user45493 Jan 2 '17 at 18:32
  • $\begingroup$ Is the order important? $\endgroup$ – corey979 Jan 2 '17 at 19:07
0
$\begingroup$

If the order of the sublists doesn't matter, simply

Intersection[Sort /@ G1, Sort /@ G2]

{}

If the order of (one) of the repeating sublists is to be preserved, then there's ContainsAll:

f[a_, b_] := 
 DeleteCases[#, {}, Infinity] & @ Flatten[#, 1] & @
  Table[ If[ContainsAll[a[[i]], b[[j]]], a[[i]], Nothing], 
    {i, 1, Length@a}, {j, 1, Length@b}]

which on G1 and G2 gives {}.


A smaller case:

a1 = {1, 2, 3, 4};
b1 = {2, 3, 4, 5};
a = Subsets[a1, {3}];
b = RandomSample /@ Subsets[b1, {3}];

f[a, b]

{{2, 3, 4}}

and

f[b, a]

{{3, 4, 2}}

$\endgroup$
0
$\begingroup$
G1=Sort/@G1;
G2=Sort/@G2;

Will get rid of order differences for entries in group elements, if that is useful to you.

its=Intersection[G1,G2]

Will be non-empty if there is at least one entry shared by G1 and G2 (and will contain them). Afterwards you can add to this list by searching for repetitions i.e. in G1 only

Do[
    If[G1[[i]]===G1[[j]],AppendTo[its,G1[[i]]];];
,{i,1,Length[G1]-1},{j,i+1,Length[G1]}]
its

And similarly for G2.

If you are only interested to find repetitions within G1 separately (or G2 separately), run its={} before the do-loop above and ignore the intersection command.

Also, i.e.

Length[G1]-Length[DeleteDuplicates[G1]]

Will tell you just how many identical entries there are in G1 (similarly for G2).

$\endgroup$
  • $\begingroup$ That is not true; consider Intersection[{{1, 2}, {2, 3}}, {{2, 1}, {3, 4}}] and the OP said that the order isn't important, so {1,2} and {2,1} are repetitions. As for the Do: DeleteDuplicates and Complement is sufficient. $\endgroup$ – corey979 Jan 2 '17 at 22:48
  • $\begingroup$ I believe the OP meant that the order of subsets is irrelevant, not the order of each entry in each sublist. I will add a sorting to avoid complications with that. $\endgroup$ – Kagaratsch Jan 2 '17 at 22:51
  • $\begingroup$ Added the optional sorting. $\endgroup$ – Kagaratsch Jan 2 '17 at 22:56
  • $\begingroup$ Don't have mathematica in front of me right now to test, but i think that there might be a non-zero chance that i.e. Complement[{a,a},{a}] actually returns {}. Thats why I went with the adhoc failproof solution. $\endgroup$ – Kagaratsch Jan 2 '17 at 23:05
0
$\begingroup$

Here's a more compact way to implement the previous suggestions:

G3 = Sort /@ Join[G1, G2];
Replace[Last@
  Reap[Length@Position[G3, #] > 1 && Sow@# & /@ G3], {v : {___}} :> v]

And then just to check that it works we'll try it on a dataset with only overlaps:

G3 = Sort /@ Join[G1, G1];
Length@Replace[
  Last@Reap[
    Length@Position[G3, #] > 1 && Sow@# & /@ G3], {v : {___}} :> v]
$\endgroup$