# Conditional matches in sets of 3-tuples

Suppose that the data is a collection of 3-tuples:

   data={{{0, 1, 1}, {0, 1, 1}, {0, 0, 1}}, {{1, 0, 0}, {0, 1, 0}, {1, 1,
1}}, {{1, 0, 1}, {0, 1, 0}, {0, 0, 0}}, {{1, 1, 1}, {1, 1, 1}, {1,
0, 0}}, {{1, 0, 1}, {1, 0, 0}, {0, 0, 0}}, {{1, 1, 1}, {1, 1,
1}, {0, 0, 0}}, {{0, 1, 0}, {0, 0, 0}, {0, 1, 0}}, {{0, 1, 1}, {0,
0, 1}, {0, 0, 1}}, {{0, 1, 1}, {1, 0, 1}, {1, 1, 1}}, {{0, 1,
1}, {0, 1, 1}, {1, 0, 0}}, {{1, 1, 0}, {0, 1, 1}, {0, 0, 0}}, {{0,
0, 0}, {1, 1, 1}, {1, 1, 0}}, {{1, 1, 1}, {1, 1, 1}, {1, 0,
0}}, {{0, 0, 0}, {0, 1, 0}, {0, 1, 0}}, {{0, 1, 0}, {0, 1, 0}, {1,
1, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 1, 0}, {1, 0,
1}, {0, 1, 1}}, {{0, 0, 1}, {0, 1, 0}, {0, 1, 1}}, {{1, 1, 1}, {1,
1, 0}, {1, 1, 1}}, {{0, 0, 1}, {0, 0, 1}, {0, 0, 1}}, {{1, 0,
0}, {0, 0, 1}, {1, 0, 0}}, {{1, 0, 1}, {1, 1, 0}, {1, 1, 0}}, {{1,
0, 1}, {1, 1, 1}, {1, 0, 1}}, {{1, 1, 1}, {1, 0, 0}, {0, 1,
0}}, {{1, 0, 1}, {0, 0, 0}, {1, 0, 1}}, {{0, 0, 0}, {0, 0, 0}, {0,
1, 1}}, {{0, 1, 0}, {0, 1, 0}, {1, 0, 1}}, {{1, 1, 1}, {1, 0,
0}, {1, 0, 0}}, {{1, 0, 0}, {0, 0, 0}, {0, 1, 1}}, {{0, 0, 0}, {1,
0, 1}, {1, 1, 0}}, {{1, 0, 1}, {0, 1, 1}, {1, 1, 1}}, {{0, 1,
1}, {0, 1, 1}, {1, 0, 0}}, {{0, 0, 0}, {0, 0, 1}, {0, 0, 0}}}


How to find only those set of 3 tuples in the data where the 2nd and 3rd elements of their 1st 3-tuple equals the first and the second elements of the 2nd 3-tuple and that the 2nd and the 3rd elements of the 2nd 3-tuple equals the 1st and 2nd element of the 3rd 3-tuple.

Select[Most[Rest /@ #] == Rest[Most /@ #] &] @ data

{{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
{{0, 1, 0}, {1, 0, 1}, {0, 1, 1}},
{{1, 0, 1}, {0, 1, 1}, {1, 1, 1}}}


If I understood you correctly, something like this would work

Cases[data,{{_,a_,b_},{a_,b_,c_},{b_,c_,_}}]

(* {{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
{{0, 1, 0}, {1, 0, 1}, {0, 1, 1}},
{{1, 0, 1}, {0, 1, 1}, {1, 1, 1}}} *)

Pick[
data,