With
In[1]:= Clear[data]
data = {{{1}, {2}, {1, 2, 3}}, {{1}, {3}, {1, 2, 3}}, {{1}, {1,
2}, {1, 2, 3}}, {{1}, {2, 3}, {1, 2, 3}}, {{2}, {3}, {1, 2,
3}}, {{2}, {1, 2}, {1, 2, 3}}, {{2}, {2, 3}, {1, 2, 3}}, {{3}, {1,
2}, {1, 2, 3}}, {{3}, {2, 3}, {1, 2, 3}}, {{1, 2}, {2, 3}, {1, 2,
3}}};
one implements the conditions straightforward
(* it is actually a conditional condition *)
Clear[wierzC1, wierzC]
wierzC1[l_List] := True /; Length[l] == 1
wierzC1[l_List] := (Length[l] -
Length[Select[
Partition[l, 2,
1], ((#[[1, 1]] == #[[2, 1]]) || (#[[1, -1]] == #[[
2, -1]])) &]] == 1) /; Length[l] > 1
(* preconditions:
p[i]: list of lists without sublists
p[ii]: no empty sublists
p[iii]: length of the sublists in list is monoton
*)
wierzC[l_List] := Block[{l0 = Length /@ l, sub1 = {}},
If[Length[Cases[l0, 1]] > 1, (* condition 2 *)
sub1 = Select[l, (Length[#] == 1) &];
If[ContainsAny[
Abs[Dot[{-1, 1}, #]] & /@
First[Flatten[Tuples[sub1, {2}], {3}]], {1}],
False, (* else: condition 1 for the rest *)
wierzC1[Complement[l, sub1]]
], (* else: condition 1 *)
wierzC1[l]
]
] /; (And @@ (VectorQ /@
l)) && (And @@ (NonNegative /@ (Dot[{-1, 1}, #] & /@
Partition[Length /@ l, 2, 1]))) && !ContainsAny[l, {{}}]
to reach the result
In[8]:= Select[data, wierzC]
Out[8]= {{{1}, {3}, {1, 2, 3}}, {{1}, {1, 2}, {1, 2, 3}}, {{2},
{1, 2}, {1, 2, 3}}, {{2}, {2, 3}, {1, 2, 3}}, {{3}, {2, 3}, {1, 2, 3}}}
even in a language with an overwhelming rich set of keywords it is more often than not the case that a single word is not enough to let it do what you want it to do.