The following one-liner does the job.
Clear["Global`*"];
listF = {{7, 2}, {2, 6}, {8, 1}, {1, 7}, {11, 8}, {6, 11}};
newD = {{{2, 7}, {7, 9}, {9, 2}}, {{7, 2}, {2, 6}, {6, 7}}, {{7,
2}, {2, 6}, {6, 7}}, {{11, 6}, {6, 2}, {2, 11}}, {{8, 1}, {1,
7}, {7, 8}}, {{11, 1}, {1, 8}, {8, 11}}, {{1, 5}, {5, 7}, {7,
1}}, {{8, 1}, {1, 7}, {7, 8}}, {{11, 1}, {1, 8}, {8, 11}}, {{11,
8}, {8, 6}, {6, 11}}, {{11, 6}, {6, 2}, {2, 11}}, {{11, 8}, {8,
6}, {6, 11}}};
Pick[newD,
Map[FreeQ[
Sequence @@@ (Permutations[#, {Length@#}] & /@ listF)
, #] &, newD, {-2}]
]
Results are at the end of the post.
The explanation is next.
Step 1
While comparing sublist entries in newD
with listF
, each point in listF
is supposed to represent all its permutations of the same length as well. For instance:
{Permutations[{2, 7}, {2}], Permutations[{1, 5, 9}, {3}]} // Grid
To this end, let's define and augment the listF
with the proper permutations:
listFnew = Sequence @@@ (Permutations[#, {Length@#}] & /@ listF)
{{7, 2}, {2, 7}, {2, 6}, {6, 2}, {8, 1}, {1, 8}, {1, 7}, {7, 1}, {11,
8}, {8, 11}, {6, 11}, {11, 6}}
Step2
A yet unknown function f
can be directly applied to each entry in newD
to determine if it (or one of its permutations) is part of/absent from the augmented list listFnew
.
Map[f, newD, {-2}]
{{f[{2, 7}], f[{7, 9}], f[{9, 2}]}, {f[{7, 2}], f[{2, 6}], f[{6,
7}]}, {f[{7, 2}], f[{2, 6}], f[{6, 7}]}, {f[{11, 6}], f[{6, 2}],
f[{2, 11}]}, {f[{8, 1}], f[{1, 7}], f[{7, 8}]}, {f[{11, 1}], f[{1,
8}], f[{8, 11}]}, {f[{1, 5}], f[{5, 7}], f[{7, 1}]}, {f[{8, 1}],
f[{1, 7}], f[{7, 8}]}, {f[{11, 1}], f[{1, 8}], f[{8, 11}]}, {f[{11,
8}], f[{8, 6}], f[{6, 11}]}, {f[{11, 6}], f[{6, 2}], f[{2,
11}]}, {f[{11, 8}], f[{8, 6}], f[{6, 11}]}}
To this end a selector function assigns a True
/False
after checking absence of membership in the augmented list as required.
sel = Map[FreeQ[listFnew, #] &, newD, {-2}]
{{False, True, True}, {False, False, True}, {False, False, True},
{False, False, True}, {False, False, True}, {True, False, False},
{True, True, False}, {False, False, True}, {True, False, False},
{False, True, False}, {False, False, True}, {False, True, False}}
Step 3
Pick[newD, sel]
Result
{{{7, 9}, {9, 2}}, {{6, 7}}, {{6, 7}}, {{2, 11}}, {{7, 8}}, {{11,
1}}, {{1, 5}, {5, 7}}, {{7, 8}}, {{11, 1}}, {{8, 6}}, {{2, 11}},
{{8, 6}}}
DeleteCases[newD, Alternatives@@Join[listF, Reverse[listF, {2}]]]
(untested). $\endgroup$Alternatives
parts works but there is a trick thatnewD
has sub-lists and the code needs to apply to those sub-lists. $\endgroup$DeleteCases
in documentation. Or you could use:newD /. Thread[Join[listF, Reverse[listF, 2]] -> Nothing]
$\endgroup$DeleteCases[newD, Alternatives @@ Join[listF, Reverse[listF, {2}]], 2]
. that woks. $\endgroup$DeleteCases[newD, # | Reverse[#, {2}] , {2}] &@ (Alternatives @@ listF)
. To delete just one element from each sublist, maybe:Function[x, DeleteCases[x, # | Reverse[#, {2}] , {1}, 1] &@ (Alternatives @@ listF)] /@ newD
$\endgroup$